program problem

Hello im a newbie and I dont understand c++ that much but im still learning.
I can't seem to find what my error is for this basic program...Mind helping me and showing me the way?

#include <iostream>

using namespace std;
int a;
int b;
int main ()
{
cout << "hello sajjad!";
cout <<"put in your age...";
cin>> a;
}
//Person was born on feb. 29(leap year)
if (a==0<)
{
cout<< "Sajjad is";
b=a/4;
cout<<b
cout<<"YEARS OLD!!!";
cout<<"HAHAHA!!!";
return 0;
}

else (a!=0<)
{
cout>> "UGLY!HUGLY!FUGLY!";
return0;
}
First thing first, next time use the code tag (the <> symbol on the right under Format) to make the code easier to see. The if and else statement is not in any function, I think you main to put them in the main function i.e like this
1
2
3
4
5
6
7
8
9
10
11
int main()
{
    if ()
   {
      //code here
   }
   else ()
   {
       //code here
   }
}


Your main function should also return something, usually return 0; and I do not think your comparisons are valid.
what he said, and
cout<<b;
Last edited on
use an IDE
Thank you ill remember that but now it shows this:
sajjads age sc.cpp(13): error C2447: '{' : missing function header (old-style formal list?)

Any Idea to what that means?And also I don't know what an IDE is yet...Im only on p.35 of 144 on the guide for c++...
Last edited on
IDE stand for Integrated Development Environment; it is used to help coding and compiling programs easier. For the error, if you post the code again, this time use the <> tag, it would help us see what you did wrong.
There is a closing } after cin>> a;. This means main function ends until there so compiler giving error.
Place a closing bracket at the end.

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
#include <iostream>

using namespace std;
int a;
int b;
int main ()
{
cout << "hello sajjad!";
cout <<"put in your age...";
cin>> a;

//Person was born on feb. 29(leap year)
if (a==0<)
{
cout<< "Sajjad is";
b=a/4;
cout<<b
cout<<"YEARS OLD!!!";
cout<<"HAHAHA!!!";
return 0;
}

else (a!=0<)
{
cout>> "UGLY!HUGLY!FUGLY!";
return0;
}
}
Last edited on
This: if (a==0<) is wrong, you need to skip the '<' : if (a==0) (also in line 23)

And this: cout>> "UGLY!HUGLY!FUGLY!"; should be: cout<< "UGLY!HUGLY!FUGLY!";
Last edited on
Topic archived. No new replies allowed.