Author Topic: Help My program doesn;t work, my first attempt has a....  (Read 3357 times)

Zophixan

  • *
  • Posts: 182
    • View Profile
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;

}

Sephiroth 3D

  • *
  • Posts: 1679
    • View Profile
    • ModCitizen 42
Help My program doesn;t work, my first attempt has a....
« Reply #1 on: 2002-10-31 17:23:09 »
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]

#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;
}

Zophixan

  • *
  • Posts: 182
    • View Profile
LOL
« Reply #2 on: 2002-10-31 22:20:01 »
Thanks but I solved it already!

mirex

  • *
  • Posts: 1645
    • View Profile
    • http://mirex.mypage.sk
Help My program doesn;t work, my first attempt has a....
« Reply #3 on: 2002-11-04 11:59:04 »
And few lines could be thrown away, because IMHO last case will be never executed. And assignment operator is '='; '==' is comparison.

Code: [Select]
#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!";
}