i need help with this error in the code

it says 10:1: error: expected unqualified-id before 'do' this idk what to do

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
34
35
36
37
38
  // Example program
#include <iostream>
#include <string>
#include <cstdlib>
#include <time.h>
using namespace std;
int numberOfGuesses=0;

int main();
do
{
     cout << "Enter your number: ";
     cin >> guess;

     if (guess < number)
     {
           cout << "Your number is less than the secret number" << endl;
            numberOfGuesses++;
      }
     else if (guess > number)
      { 
           cout << "Your number is more than the secret number" << endl;
           numberOfGuesses++;
       } 
       else
       {
           cout << "Your guess is correct!" << endl;
           cout<<"You guessed in "<<numberOfGuesses<<" tries!";
        }
} 
while (guess != number);

system("PAUSE");

return 0;

}
The problem is the ; after main in line 9. Put a { there and should compile just fine.
; is used to declare a function, which is often found in header files, so the function body is defined elsewhere. In this case, do would be outside any function body, which is not allowed.
Topic archived. No new replies allowed.