I'm very new to c++, and having alot of issues with a project I have to do. The project is
Write a program in which:
A random integer between 0 and 500 is generated at the beginning.
The user is asked to guess the number.
The user is told whether her/his guess was too high or too low, and asked to guess again, until the guess is correct.
I just cannot get the program to loop. When I run it, I enter a number and it says "Sorry, too low", and then nothing happens.
I'd really appreciate any help as I'm new to this and really want to learn! The code I have so far;
#include <iostream>
#include <cstdlib>
using namespace std;
int main()
{
int num, guess;
num = rand() % 500 ;
do{
cout<< "Guess the random number: ";
cin>> guess;}
while (guess < num);
cout<< "Sorry, too low.";
while (guess > num);
cout<< "Sorry, too high.";
while (guess != num);
cout<< "Congratulations, you got it!";
return 0;
}
by the way, not asking for the solution, just a few pointers about where i went wrong!! thanks.