Plz help a coding newbie!

This is a discussion on Plz help a coding newbie! within the C++ Programming forums, part of the General Programming Boards category; I was trying to code a program on one of these sites tutorials but some of modifications made a parse ...

  1. #1
    Registered User
    Join Date
    Oct 2002
    Posts
    18

    Talking Plz help a coding newbie!

    I was trying to code a program on one of these sites tutorials but some of modifications made a parse error on line 35 (what is a parse error) Could someone tell me what I have done wrong and help me correct it, the code:

    Code:
    #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;
    
    }
    Last edited by Zophixan; 10-31-2002 at 08:41 AM.

  2. #2
    Code Monkey Davros's Avatar
    Join Date
    Jun 2002
    Posts
    812

    Talking

    This is a joke yeh?
    OS: Windows XP
    Compilers: MinGW (Code::Blocks), BCB 5

    BigAngryDog.com

  3. #3
    ...
    ... is offline
    Registered User
    Join Date
    Feb 2002
    Posts
    465

    Re: Plz help a coding newbie!

    Code:
    cout<<"you are older than me!"

    a semicolon after that line would help.
    I came up with a cool phrase to put down here, but i forgot it...

  4. #4
    Registered User
    Join Date
    Oct 2002
    Posts
    18
    joke? kinda but still I wanted to know why it didn;t work lol

  5. #5
    Code Monkey Davros's Avatar
    Join Date
    Jun 2002
    Posts
    812
    I thought you were joking because there is non-functional part of you code, which I assumed was deliberated. Look:

    Code:
    if (age == 14)
    ...
    else if (age < 14)
    ...
    else if (age > 14)
    ...
    else
    {
      cout<<"I have no idea how old you are";
    }
    That last clause will never be executed. There are only three valid conditions. Either an integer number is equal to 14, less than, or greater than 14. There is no 4th.

    You could re-write your code as:

    Code:
    if (age == 14)
    ...
    else if (age < 14)
    ...
    else
    {
      cout<<"you are older than me!"
    }
    OS: Windows XP
    Compilers: MinGW (Code::Blocks), BCB 5

    BigAngryDog.com

  6. #6
    Registered User GreenCherry's Avatar
    Join Date
    Mar 2002
    Posts
    65
    Ya, I was kinda lost, cuz even if it was a char is would still be one of the three.

    YAAY! This is my 50th post!!!
    I have a rabbit in my pants! Please be happy for me.

  7. #7
    ...
    ... is offline
    Registered User
    Join Date
    Feb 2002
    Posts
    465
    well, looking at it logically, the only input that is put into the program is the persons age, and if they dont put in their age the program will wait until they do.

    there is no possible way the computer can not know your age. if you claim to be 'apostrophe' years old, then the computer accepts it and therefore knows how old you are ( apostrophe years old ).

    basically, that is a superfluous addition to your program, mr zophixan.
    I came up with a cool phrase to put down here, but i forgot it...

  8. #8
    Registered User
    Join Date
    Oct 2002
    Posts
    18
    I just noticed that part! That is filled in now!, I forgot about it because of the errors!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Newbie c programmer need assistance plz...
    By Nexus-ZERO in forum C Programming
    Replies: 17
    Last Post: 12-27-2007, 04:05 PM
  2. Newbie needs help plz
    By boffinson in forum C++ Programming
    Replies: 22
    Last Post: 07-29-2006, 04:25 AM
  3. im newbie to opengl, help plz
    By NecroFromHell in forum C++ Programming
    Replies: 4
    Last Post: 05-14-2006, 09:24 PM
  4. HI .. newbie to the board... need some help plz
    By Arwen27 in forum C Programming
    Replies: 3
    Last Post: 04-28-2002, 08:27 AM
  5. Newbie Source Code question. Hlp Plz?
    By BOOGIEMAN in forum Game Programming
    Replies: 4
    Last Post: 12-14-2001, 04:30 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21