•
•
•
•
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
![]() |
•
•
Join Date: Oct 2007
Posts: 40
Reputation:
Rep Power: 2
Solved Threads: 0
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.
cplusplus Syntax (Toggle Plain Text)
#include <iostream> #include <cstdlib> #include <ctime> using namespace std; int main() { srand(time(0)); int randomNumber = rand() % 1000 + 1; int guess = 0; cout << "\tThe Number Guessing Game\n\n"; do { cout << "Enter your guess (#1-1000): "; cin >> guess; if (guess < randomNumber) cout << "Your guess was too low\n\n"; if (guess > randomNumber) cout << "Your guess was too high\n\n"; } while (guess != randomNumber); cout << "\nCongratulations! You've guessed the number.\n\n"; system("pause"); return 0; }
Last edited by Narue : Nov 9th, 2007 at 1:10 pm. Reason: Added code tags
•
•
Join Date: Jul 2005
Posts: 1,285
Reputation:
Rep Power: 9
Solved Threads: 175
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 ![]() |
•
•
•
•
•
•
•
•
DaniWeb C++ Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
Similar Threads
- error in guessing game (Python)
- C++ prime number program help (C++)
- Prime Number program.. with a twist (C)
- Guessing game (C++)
- Something similar to def in Tkinter (Python)
- Guess Number Game (Problem) (Java)
- Program help (C++)
Other Threads in the C++ Forum
- Previous Thread: printf and reference issue
- Next Thread: Cant see the error



Linear Mode