User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the C++ section within the Software Development category of DaniWeb, a massive community of 456,233 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,778 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our C++ advertiser: Programming Forums
Views: 1314 | Replies: 4
Reply
Join Date: Oct 2007
Posts: 40
Reputation: dblbac is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 0
dblbac dblbac is offline Offline
Light Poster

Help Help with guess a number program

  #1  
Nov 9th, 2007
i have made the following but the user should get 10 chances to guess the right number. after the 10 guesses or if the the guesser gets it correct it should ask if the player wants to play again and react accordingly.
  1. #include <iostream>
  2. #include <cstdlib>
  3. #include <ctime>
  4.  
  5. using namespace std;
  6. int main()
  7. {
  8. srand(time(0));
  9. int randomNumber = rand() % 1000 + 1;
  10. int guess = 0;
  11. cout << "\tThe Number Guessing Game\n\n";
  12.  
  13. do
  14. {
  15. cout << "Enter your guess (#1-1000): ";
  16. cin >> guess;
  17.  
  18. if (guess < randomNumber)
  19. cout << "Your guess was too low\n\n";
  20.  
  21. if (guess > randomNumber)
  22. cout << "Your guess was too high\n\n";
  23.  
  24. } while (guess != randomNumber);
  25.  
  26. cout << "\nCongratulations! You've guessed the number.\n\n";
  27. system("pause");
  28.  
  29. return 0;
  30. }
Last edited by Narue : Nov 9th, 2007 at 1:10 pm. Reason: Added code tags
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Sep 2004
Posts: 6,510
Reputation: Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of 
Rep Power: 31
Solved Threads: 487
Super Moderator
Narue's Avatar
Narue Narue is online now Online
Expert Meanie

Re: Help with guess a number program

  #2  
Nov 9th, 2007
>after the 10 guesses or if the the guesser gets it correct it
>should ask if the player wants to play again and react accordingly.
So wrap the whole thing in another loop and prompt for whether the user wants to play again.
I'm here to prove you wrong.
Reply With Quote  
Join Date: Oct 2007
Posts: 40
Reputation: dblbac is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 0
dblbac dblbac is offline Offline
Light Poster

Re: Help with guess a number program

  #3  
Nov 9th, 2007
thanks i will try that, but how do i go about doing that. i am a novice at this stuff and working on my own. i have been reading my text but can't seem to find it. any help would be appreciated
Reply With Quote  
Join Date: Jul 2005
Posts: 1,285
Reputation: Lerner is just really nice Lerner is just really nice Lerner is just really nice Lerner is just really nice 
Rep Power: 9
Solved Threads: 175
Lerner Lerner is online now Online
Nearly a Posting Virtuoso

Re: Help with guess a number program

  #4  
Nov 9th, 2007
To look it up it's frequently called a nested loop since one loop sits inside another. Any type loop can be used in either position. Can have more than one nested loop, more than one layer of nested loops, etc.
outer loop //control whether to guess a number 
   generate random number to guess
   inner loop
      whatever
   end inner loop
   determine whether to continue or not
end outer loop 
Reply With Quote  
Join Date: Oct 2007
Posts: 40
Reputation: dblbac is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 0
dblbac dblbac is offline Offline
Light Poster

Re: Help with guess a number program

  #5  
Nov 9th, 2007
thanks i appreciate it
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb C++ Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the C++ Forum

All times are GMT -4. The time now is 5:06 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC