error: expected unqualified-id before '{' token

So I just started c++ about an hour ago. I'm currently following a guide to help me learn, but I can't get past this error error: expected unqualified-id before '{' token. I've tried google and other forums, but nothing.
Here's my code, I hope yall can help!

1
2
3
4
5
6
7
8
9
10
11
#include <iostream>
using namespace std;
int main();
{
variable x = 5;
variable y = 7;
    cout "\n"
    cout << x + y << " " << x * y
    cout "\n";
return 0;
}
There is no such thing as "variable", you have to choose a type to represent the variable. (char, short, int, long, float, double, sound familiar?)
You're missing a semicolon on line 7.
You're missing a semicolon on line 8.

You should use endl instead of "\n" for putting a new line out, if you don't there are cases where you may not see your output even if the console stays open for an extended period of time.
Last edited on
alright, so I changed it to
1
2
3
4
5
6
7
8
9
10
11
#include <iostream>
using namespace std;
int main();
{
int x = 5;
int y = 7;
    cout "endl"
    cout << x + y << " " << x * y;
    cout "endl";
return 0;
}


but I'm still getting the same error :( I'm using Codeblock 10.05
If there's a better compiler that you recommend, it would be much appreciated.
You still didn't add a semicolon to the end of line 7. Also, it needs to be cout << endl;
Also, you really should remove that semicolon after int main() as it is the reason you're getting that error.
Last edited on
To use endl; correctly, it's cout << endl; or cout << "Print this to screen" << endl;
Last edited on
Alright, I got rid of the semi colon in line 3.
But now I'm getting an error on lines 7 and 9 saying error: expected ';' before string constant
Sorry, I edited my post after I noticed that. It needs to be cout << endl;
Haha, yup. cout << "Print this to screen" << endl; worked :D Thanks so much mate!
Topic archived. No new replies allowed.