Need Help With Assignment Due Today

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!.....................
This is what i have so far.......
#include <iostream>
using namespace std;


int main ()
{
int n;
int r= rand()%100;
cout<<"Guess the random number"<<endl;
cout<<"Enter your guess";
cin>>n;
if (n!=r) cout<<"Wrong!";
else if (n=r) cout<<"You got it!";
system("pause");
return 0;
}
Just create some bool flag and set it to true. Then create a while loop that runs while the flag is true. Put the whole "Enter your guess" and that if/else statement in the while loop, and set the flag to false when the user gets the number right.
how do i do that freddy??
ok im almost there i kinda got it but the program should end after i guess the right answer but it keeps going. this is what i have......

#include <iostream>
using namespace std;
int main ()
{
int n;
int r= rand()%5;
do {
cout<<"Guess the random number"<<endl;
cout<<"Enter your guess"<<" ";
cin>>n;
if (n!=r) cout<<"Wrong!";
else if (n=r) cout<<"You got it!"<<endl;
}
while (n=r);
system("pause");
return 0;
}
Topic archived. No new replies allowed.