Help My program doesn;t work, my first attempt has a....

  • Thread starter Thread starter Zophixan
  • Start date Start date
Status
Not open for further replies.
Z

Zophixan

Guest
There is a parse error on line 35


#include <iostream.h>

int main()

{

int age;

cout<<"plz input your age: ";

cin>>age;

if (age<14)

{

cout<<"you are younger than me!";

}

else if(age==14)

{

cout<<"you are the same age as me";

}

else if(age>14)

{

cout<<"you are older than me!"

}

else

{

cout<<"I have no idea how old you are";

}

return 0;

}
 
cout<<"you are older than me!"

should be

cout<<"you are older than me!";

you forgot the ; on it.

It would probably be a good idea to make a myage variable and set that to your age. It'll save some time when your age changes.

These changes should make your whole code look something like this:

Code: [Select]
Code:
#include <iostream.h>int main(){ int age; int myage; myage==14; cout<<"plz input your age: "; cin>>age; if (age<myage){  cout<<"you are younger than me!"; }else if(age==myage){  cout<<"you are the same age as me"; }else if(age>myage){  cout<<"you are older than me!"; }else{  cout<<"I have no idea how old you are"; } return 0;}
 
And few lines could be thrown away, because IMHO last case will be never executed. And assignment operator is '='; '==' is comparison.

Code: [Select]
Code:
#include <iostream.h> void main() { int age; int myage = 14;cout<<"plz input your age: "; cin>>age; if (age<myage)  cout<<"you are younger than me!"; else if(age==myage)  cout<<"you are the same age as me"; else   cout<<"you are older than me!"; }
 
Status
Not open for further replies.
Back
Top