Thread: a big problem

  1. #1
    Registered User
    Join Date
    Jul 2003
    Posts
    13

    Post a big problem

    can any1 tell me wut's the problem of this code:
    #include <iostream.h>
    int main()
    {
    int choice;
    cout<<"Please choose: \n";
    cout<<"1.ID program\n";
    cout<<"2.2nd program\n";
    cout<<"3.Quit\n";
    cout<<" I Choose:";
    cin>>choice;
    if(choice==1)
    {

    cout<<"ok lets start!\n";
    cout<<"Welcome to shady's first c++ program\n";
    cout<<"wut's ur name?\n";
    char name[50],action[50];
    cin.getline (name, sizeof (name));
    cout<<"Welcome "<<name <<"\n";
    cout<<"wut do u wanna do? \n";
    cin.getline (action, sizeof (action));
    cout<<"no u can't "<<action <<"\n";
    }

    if(choice==2)
    {
    cout<<"ok lets start!\n";
    cout<<"Welcome to shady's second c++ program\n";
    char name[90];
    cout<<"wut's ur name?\n";
    cin.getline(name, sizeof (name));
    cout<<"wut's your gender? \n";
    char gender[90];
    cin.getline(gender, sizeof (gender));
    cout<<"wut's ur birthdate?\n";
    char birthdate[90];
    cin.getline(birthdate, sizeof (birthdate));
    cout<<"Your name: "<<name <<"\n";
    cout<<"Your gender: "<<gender <<"\n";
    cout<<"Your birthdate: "<<birthdate <<"\n";
    }
    if (choice==3)
    {
    cout<<"Byebye";
    }
    else
    {
    cout<<"This is not an option";
    }
    return 0;
    }

  2. #2
    pronounced 'fib' FillYourBrain's Avatar
    Join Date
    Aug 2002
    Posts
    2,297
    1st, use code tags and indent. makes code easier to read.

    2nd, use endl at the end of your cout statements, it flushes the buffer and causes a "\n" internally.

    3rd, your ifs on 2 and 3 should be "else if"

    4th, don't you want to loop and do the menu again if you aren't choosing 3?
    "You are stupid! You are stupid! Oh, and don't forget, you are STUPID!" - Dexter

  3. #3
    Registered User
    Join Date
    Jul 2003
    Posts
    26
    You will also need to add cin.ignore() after cin>>choice. It will get rid of the return at the end of the string, so your first getline in the IF (whichever is executed) won't be empty.
    --LiKWiD
    Becoming un-noobified one day at a time.

  4. #4
    Registered User
    Join Date
    Nov 2002
    Posts
    1,109
    What exactly are you having problems with?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. big number problem
    By mad_muppet in forum C Programming
    Replies: 11
    Last Post: 08-26-2008, 12:54 AM
  2. Plzzzzz Help Me >>> Big Problem
    By AHMED KHALAF in forum C Programming
    Replies: 2
    Last Post: 12-09-2004, 07:31 AM
  3. [Help] C++ Problem
    By Oxide in forum C++ Programming
    Replies: 3
    Last Post: 10-09-2004, 09:05 PM
  4. half ADT (nested struct) problem...
    By CyC|OpS in forum C Programming
    Replies: 1
    Last Post: 10-26-2002, 08:37 AM
  5. binary tree problem - help needed
    By sanju in forum C Programming
    Replies: 4
    Last Post: 10-16-2002, 05:18 AM