I'm new to this site and am desperate for help. I'm learning C++ for university, and have just received my second project. it goes like this:
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 have made numerous attempts, and just cant get it to work!! This is what i did;
#include <iostream>
#include <cstdlib>
using namespace std;
int main()
{
int num, guess;
do{
num=rand()%500;
cout<< "Guess the secret number: ";
cin>> guess;}
while (guess<num);
cout<< "Sorry, that guess is too low.";
while (guess>num);
cout<< "Sorry, that guess is too high.";
while (guess!=num);
cout<< "Congratulations, you got it!";
return 0;
}
I know this is really simply, but I just cant get my head round it! I don't want to be just given the answer by the way, just some pointers where i might have gone
wrong, because I really want to learn this. Any help would be appreciated! Thanks