Doing arithmetic

I am doing arithmetic but everytime i compile the code it responds wiht this "expected unqualified-id before before '}' token"
Here is the code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#include <iostream>
using namespace std ;

int main() ;
{
int a = 8 , b = 4 ;

cout << "Addition result: " << ( a + b ) << endl ;
cout << "Subtraction result: " << ( a - b ) << endl ;
cout << "Multiplication result: " << ( a * b ) << endl ;
cout << "Division result: " << ( a / b ) << endl ;
cout << "Modulus result: " << ( a % b ) << endl ;
cout << "Postfix increment: " << a++ << endl ;
cout << "Postfix result: " << a << endl ; 
cout << "Prefix increment: " << ++b << endl ;
cout << "Prefix result: " << b << endl ;

return 0 ;
}
Lose the ; at the end of line 4.

int main();

is how to forward declare the function main

1
2
3
4
5
6
int main()
{
    // etc

    return 0;
}


is how to define it.

The error message is attempting to tell you it expects something before the {

The ; on line 4 ended the declaration statement, to { is the first thing the compiler found when it started on the next statement.

Andy

Last edited on
Oh okay thanks, the problem was with the ";" after int main, the return didn't matter. Anyway a million thanks :D
Topic archived. No new replies allowed.