error

kindly tell me whats the error in this program?i am using code blocks and its giving error in braces.plz help


#include <iostream>
using namespace std;

int main();
{
if (x>0)
cout<<"x is positive";
else if (x<0)
cout<<"x is negative";
else
cout<<"x is 0"

return 0;
}
remove the semicolon from after int main(). It should just be int main() {
there is a semicolon after int main(), which does not go there
x is undeclared
and missing semicolon after your last cout statement
are you wanting input from the user?
you were missing some brackets and semi colons also.

This is what it looks like working. I added in an int x to make it compile and run. but you coudl change it to cin or something

1
2
3
4
5
6
7
8
9
10
11
#include <iostream>
using namespace std;

int main()
{
int x = 1;
if (x>0) {cout<<"x is positive";}
else if (x<0) {cout<<"x is negative";}
else {cout<<"x is 0";}
return 0;
}
i removed the semicolons but its showing the error now...
error:expected ';' before 'return'

after that when i removed the semicolon from return it shows
error: expected ';' before 'return'

what to do now?help

on line 9 you are missing a semicolon with your cout statement
thank you every one for helping,.,.,take care :)
Topic archived. No new replies allowed.