how to loop properly

I'm new to this, so i'm still learning!

I'm trying to get the user to guess the number the computer is thinking and give the appropriate response and loop.

#include <iostream>
using namespace std;
int main()
{
int guess;
int number;
number = 4;

cout << "Try to guess what number I'm thinking of!\n";
cin >> guess;

if ( guess != number)
{
cout << "I'm sorry, try again!" << endl;
cin >> guess;
}
else ( guess == number);
{
cout << "Aww shucks, you guessed right!" << endl;
}
system ("PAUSE");
return 0;
}

ps: how do have the computer randomize the number for the "number" value.?
thanks a lot. I was just reading up on "while".

yay randomization!
Finally, i got it to work!

thanks dude!

#include <iostream>
using namespace std;
int main()
{
int number;
int guess;

cout << "Try and guess what number I'm thinking1 (1-10)\n";
cin >> guess;
number = 4;
cout << "You think it's " << 4 << "?\n";

while ( number != guess )
{
cout << "You got it wrong! Try again but you'll get it wrong again anywayz!\n";
cin >> guess;
}
cout << "Awww shucks! You got me! Here's your prize!\n";
cout << "You receive 280 gold from scoundrel.\n";

system ("PAUSE");
return 0;
}
Topic archived. No new replies allowed.