Guess my number game problem

Hello, I tried making a guess my number game, but inverted, by having the user input a number and the computer trying to guess it.
Here is the source code.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
//Guess my Number (inverted)
//The computer will guess your number

#include <iosteam>
#include <cstdlib>
#include <ctime>

using namespace std;

int main ()

{

    int myNumber,;
    string yesorno;
    cout <<"Enter a number between 1 and 10: ";
    cin >> myNumber;
    cout <<"\nYou chose "<<myNumber <<" as your number."
    
do
{
    srand(time(0)); 
    int theNumber = rand() % 10 + 1; 
    cout <<"Is your number "<<theNumber<<"?";
    cin >> yesorno;
} while (yesorno == yes);

cout <<"I won !";

return 0;
}

Last edited on
DevC++ says there is a problem in this part.

cout <<"Enter a number between 1 and 10: ";
Last edited on
#include <iosteam>
Typo.

int myNumber,;
You had an extra comma in there.

cout <<"\nYou chose "<<myNumber <<" as your number."
Missing semicolon.

} while (yesorno == yes);
I think you meant while (yesorno != "yes");?

By the way, you should only really call srand(time(0)); once in your program, so move that line above your loop.
Last edited on
Topic archived. No new replies allowed.