Help with guessing game im making
Im making a guessing game in c++. THis is my first attempt at a program. I cant figure out how to do it. Heres my code, i dont know whats wrong:
#include <iostream.h>
int main ()
{
int guess;
int num;
cout<<"Enter a guess";
cin>>guess;
if(guess = num)
{
cout>>"You guessed the right number!";
}
else
{
cout>>"Try again"
}
}
I have one more question...
It exits the program too fast when i run it. I cant see weather or not the guess was right. Is there some way to make it pause untill the user hits a key, like the SLEEP command in QBasic.
why so many include stuff?
Why do i have to include all this stuff? How am i suposed to know which to include in my programs? What do they do? Are they like libraries are in qbasic?
ok, need help with multiple tries
What I want is to have 3 tries and then have it ask if the user wants to try again. How do I do this? Heres the code I have now:
#include <iostream.h>
#include <windows.h>
int main ()
{
int guess;
int num=4; //or any other number
cout<<"Enter a guess: ";
cin>>guess;
if(guess == num)
{
cout << "You guessed the right number!";
Sleep(1000);
}
else
{
cout << "Try again" ;
Sleep(1000);
}
}