error

Nov 18, 2013 at 8:55pm
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;
}
Nov 18, 2013 at 9:00pm
remove the semicolon from after int main(). It should just be int main() {
Nov 18, 2013 at 9:03pm
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?
Nov 18, 2013 at 9:05pm
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;
}
Nov 18, 2013 at 9:05pm
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

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