Thread: Help with code?

  1. #1
    Registered User
    Join Date
    Jan 2003
    Posts
    9

    Unhappy Help with code?

    Hi, i am a total newbie and could you tell me whats wrong with this code?

    #include <iostream.h>
    #include <string.h>


    int main()

    {
    char name[20];
    char vclass[20];
    char race[20];
    int age[2000];



    cout<<"Welcome to quest for the holy pistol!"<<endl;
    cout<<"The name of the character: ";
    cin.getline(name, 20, '\n');

    cout<<"Pick a class: ";
    cin.getline(vclass, 20, '\n');

    cout<<"Pick a race: ";
    cin.getline(race, 20, '\n');

    cout<<"Age of the character: ";
    cin.getline(age, 2000, '\n');

    cout<<"Name:"<<name<<;
    cout<<"Class:"<<vclass;
    cout<<"Race:"<<race;
    cout<<"Age:"<<age;


    return 0;

    }

  2. #2
    Has a Masters in B.S.
    Join Date
    Aug 2001
    Posts
    2,263
    two things that stand out.

    >cin.getline(age, 2000, '\n');

    why is this 2000.

    >cout<<"Name:"<<name<<;

    note the extra ilegal '<<' before the semi colon

    tell us what errors your getting, you can't expect us to debug the code for you.
    ADVISORY: This users posts are rated CP-MA, for Mature Audiences only.

  3. #3
    Funniest man in this seat minesweeper's Avatar
    Join Date
    Mar 2002
    Posts
    798
    >>cin.getline(age, 2000, '\n');<<

    Also, no need for this or int age[2000]; for that matter.

    Just

    Code:
    int age;
    
    and
    
    cin>>age;
    shall suffice

  4. #4
    Registered User
    Join Date
    Jan 2003
    Posts
    9

    Lightbulb

    Finally i got it to work... i dont quite remember the error but at least i got it fixed. I am such a newbie!

    #include <iostream.h>
    #include <string.h>


    int main()

    {
    char name[20];
    char vclass[20];
    char race[20];
    int age;



    cout<<"Welcome to quest for the holy pistol!"<<endl;
    cout<<"The name of the character: ";
    cin.getline(name, 20);

    cout<<"Pick a class: ";
    cin.getline(vclass, 20);

    cout<<"Pick a race: ";
    cin.getline(race, 20);

    cout<<"Age of the character: ";
    cin>>age;

    cout<<"Name:"<<name<<endl;
    cout<<"Class:"<<vclass<<endl;
    cout<<"Race:"<<race<<endl;
    cout<<"Age:"<<age<<endl;


    return 0;

    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Extended ASCII Characters in an RTF Control
    By JustMax in forum C Programming
    Replies: 18
    Last Post: 04-03-2009, 08:20 PM
  2. Enforcing Machine Code Restrictions?
    By SMurf in forum Tech Board
    Replies: 21
    Last Post: 03-30-2009, 07:34 AM
  3. Obfuscated Code Contest
    By Stack Overflow in forum Contests Board
    Replies: 51
    Last Post: 01-21-2005, 04:17 PM
  4. Interface Question
    By smog890 in forum C Programming
    Replies: 11
    Last Post: 06-03-2002, 05:06 PM
  5. Replies: 0
    Last Post: 02-21-2002, 06:05 PM