Can someone solve this for me?

Can someone try and solve this for me? I can't find out whats wrong. Can someone try this them selves and find out what I did wrong? PLz

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
29
30
31
32
33
#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!";
	return 0;
}
}
Put your if/else statements in between the int main() brackets. OH! And dont forget return 0;!

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
int main()
{
cout << "hello sajjad!";
	cout <<"put in your age...";
	cin>> a;

if (a==0)
{
	cout<< "Sajjad is";
	b=a/4;
	cout<<b;
		cout<<"YEARS OLD!!!";
		cout<<"HAHAHA!!!";
}
else (a!=0<)

	{
		cout<< "UGLY!HUGLY!FUGLY!";
        }
}

}



Sorry I couldnt get all of it. Ive got work to do.
What does that mean I don't get it. Can you show an example?
Your braces for int main() must be around the code, like illustrated by Hazique35.
I tried what he did but I still get errors. I'm using visual c++ 2010 by the way.

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
29
30
31
32
33
#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!";
	return 0;
}
}
Last edited on
You could simplify it like this

1
2
3
4
5
6
7
8
9
10
11
12
13
int main() {
   cout << "hello sajjad, ";
   cout <<"put in your age...\n";
   cin>> a;
   if (a==0) { // why would you accept 0 as an age?
      cout<< "Sajjad is "; // notice a space is added, makes it look a bit better
      b=a/4; // this always assigns b to 0
      cout<<b;
      cout<<" YEARS OLD!!!"; // another space here
      cout<<"HAHAHA!!!";
   }
   else cout<< "UGLY!HUGLY!FUGLY!"; // ...ok
}
I don't know why when ever I do it it never seems to work. there is always an error.

fatal error LNK1169: one or more multiply defined symbols found
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include <iostream>

using namespace std;
int a;
int b;
int main() {
   cout << "hello sajjad, ";
   cout <<"put in your age...\n";
   cin>> a;
   if (a==0) { // why would you accept 0 as an age? I was thinking of replacing the variable with something that goes from 0 to infinite or somthing
      cout<< "Sajjad is "; // notice a space is added, makes it look a bit better
      b=a/4; // this always assigns b to 0
      cout<<b;
      cout<<" YEARS OLD!!!"; // another space here
      cout<<"HAHAHA!!!";
   }
   else cout<< "UGLY!HUGLY!FUGLY!"; // ...ok
}
Last edited on
There should be no code below what appears in your post above. Is there still stray code (lines 14-33 in your opening post) below main?
Your program is correct.

I think you are using more than one source files in your project and main() is already written in another file.

Maintain only one main() function for one project or you can start new project and try it there.
Last edited on
I agree with tvrameshmc. I'm pretty sure I did that when I first started.
Topic archived. No new replies allowed.