Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
HELP with do loop
#1
Code:
1. #include<iostream> 2. #include <cstdlib> 3. #include <ctime> 4. using namespace std; 5. 6. int main() 7. { 8. int tries = 0; 9. int input; 10. srand(static_cast<unsigned int>(time(0))); 11. int rand_number = rand() % 100 + 1; 12. string play_again; 13. bool sucess; 14. 15. do{ 16. do { 17. cout << "Enter a number : " << endl; 18. cin >> input; 19. tries++; 20. 21. if (input > rand_number){ 22. cout << "Too high!" << endl; 23. }else if (input < rand_number){ 24. cout << "Too low!" << endl; 25. }else if (input == rand_number){ 26. cout << "You guessed it. It took you " << tries << " tries." << endl; 27. } 28. } while (input != rand_number); 29. cout << "Do you wanna play aganin? (y/n)" << endl; 30. cin >> play_again; 31. if (play_again == "y") 32. sucess = true; 33. } while (!sucess); 34. cin.get(); 35. return 0; 36. }

0300-9520262
Get solution in 24 hour
|cpmputer & internetConfusedmileys81:[SIZE="4"][SIZE="3"]....[/SIZE][/SIZE]
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  C++ with loop code 2011-12 Vuhelper 0 978 09-18-2011, 07:09 PM
Last Post: Vuhelper
  Create new variables with a loop? in c++ 2011 -12 Vuhelper 0 2,083 08-27-2011, 08:46 PM
Last Post: Vuhelper
  Write a calculator program using a do-while loop in c++ 2011 Vuhelper 0 2,773 06-27-2011, 06:41 PM
Last Post: Vuhelper
  loop statement in c++ 2011 Vuhelper 0 2,100 06-04-2011, 10:32 PM
Last Post: Vuhelper

Forum Jump:


Users browsing this thread: 1 Guest(s)