- This topic has 2 replies, 3 voices, and was last updated 11 years, 6 months ago by trancedsailor.
- September 22, 2011 at 6:50 pm #128026wongckMember
Having our second Cars and Coffee and spreading the word. If anyone is interested. ThanksCars and Coffee 2
The next Cars & Coffee will occur on Sunday,October 16th at 9am at the Covington, Cafe du Monde.
70437 Highway 21, Covington, La.September 23, 2011 at 4:00 pm #133264trancedsailorMember
I need to write a program where the user has to guess the random number that the program makes up. The range is between 0 – 100 and the user only gets 10 tries to guess the number. If the number is too high or too low, it informs the user by saying that the random number is lower or higher.
I’m still learning Java and C++ is very new to me, even though most of the stuff is similar. The program that I have written compiles and runs, but it doesn’t seem to reach the steps that tell the user whether the number the entered is higher or lower than the random number. This is my first time using nested if’s and I probably have them ordered in a way where they aren’t being read.
Can anyone point me in the right direction so my program will follow through with the right step at the right time?
Here is my code:
int main ()
int usersChances = 0;
int MAX_VALUE = 100 + 1;
int MIN_VALUE = 0;
srand ( time(NULL) );
secretInt = rand() % 100 + 1;
while ( (usersGuess != secretInt) && (usersChances <= 9) )
cout << "The secret number is between 1 and 100.n"
<< "What is your guess? ";
cin >> usersGuess;
if ( usersGuess > MAX_VALUE && usersGuess > MIN_VALUE )
if ( usersGuess == secretInt )
cout << "Right! It took you " << usersChances << " guesses.";
if ( usersGuess < secretInt )
cout << "Too low, guess again? ";
if ( usersGuess > secretInt )
cout << "Too high, guess again? ";
cout << "Invalid guess, guess again? ";
Tips or suggestions are greatly appreciated. Thank you!September 23, 2011 at 4:09 pm #133263AnonymousInactive
Tips: Go elsewhere SPAMMER…..
- You must be logged in to reply to this topic.