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
Wrong!
Enter your guess:4
Wrong!
Enter your guess:9
Wrong!
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"<<" ";
cin>>n;
if (n!=r) cout<<"Wrong!"<<endl;
else if (n=r) cout<<"You got it!"<<endl;

}
while (n=r);
system("pause");
return 0;
}
you wrote do {...

}

while(n=r);

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.