Need Help With Assignment Due Today Almost Got it

Write a program that selects a secret random number between 0 and 99.
Then it repeatedly asks the user to guess what the number is (until the guess it correctly).
So, e.g. if the program selected 7 as the secret number then the user might see
Enter your guess: 3
Enter your guess:4
Enter your guess:9
Enter your guess:7
You Got it!.....
Program does not end when the user guesses the correct answer, thats the problem.
This is what i have so far.......

#include <iostream>
using namespace std;
int main ()
int n;
int r= rand()%5;
cout<<"Guess the random number"<<endl;
do {
cout<<"Enter your guess"<<" ";
if (n!=r) cout<<"Wrong!"<<endl;
else if (n=r) cout<<"You got it!"<<endl;

while (n=r);
return 0;
you wrote do {...



if im reading the code correctly, you do not want to continue doing things when n=r (meaning they guessed right).

should be: while(n!=r)

try it out
Thanks a lot it worked!!!!
Topic archived. No new replies allowed.