Qhimm.com Forums

Miscellaneous Forums => Scripting and Reverse Engineering => Topic started by: Zophixan on 2002-10-31 13:17:08

Title: Help My program doesn;t work, my first attempt has a....
Post by: Zophixan on 2002-10-31 13:17:08
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;

}
Title: Help My program doesn;t work, my first attempt has a....
Post by: Sephiroth 3D 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;
}
Title: LOL
Post by: Zophixan on 2002-10-31 22:20:01
Thanks but I solved it already!
Title: Help My program doesn;t work, my first attempt has a....
Post by: mirex 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!";
}