problems with guessing game

#include <iostream>
using namespace std;
int main ()
{
int number=54;
int answer;
cout << "I'm thinking of a number from one to one hundred./n";
cout << "Can you guess it?/n";
cin >> answer;
if (answer<number)
cout << "Higher./n";
cin >> answer;
else if (answer>number)
cout << "Lower./n" ;
cin >> answer;
else
cout << "You got it! The answer is ";
cout << answer << "!";

system ("PAUSE");
return 0;
}


Above is a code for a guessing game I am working on in which the player must guess correctly guess the number the computer is thinking of (54).
I don't know what I did wrong. I use visual c++.
Help?
Last edited on
At least the brackets are missing:

if (answer<number)
{
cout << "Higher./n";
cin >> answer;
}
else if (answer>number)
{
cout << "Lower./n" ;
cin >> answer;
}
else
{
cout << "You got it! The answer is ";
cout << answer << "!";
}
With this flow, there is no ability to repeat the guess....

something like this....

1
2
3
4
5
6
7
8
9
10
11
do
{
     cout << "Enter your guess: " << endl;
     cin >> answer;
     if ( answer > 54)
          cout << "Too high" << endl;
      else if (answer < 54)
          cout << "Too low";
      else
          cout << "You guessed it. The number was 54";
}while(answer != 54);



allows for guessing until the number as been picked
Topic archived. No new replies allowed.