Results 1 to 9 of 9

Thread: c++ need help

  1. #1

    Thread Starter
    Member
    Join Date
    Oct 2002
    Posts
    61

    c++ need help

    Can someone help me out this program ?

    I want write a program to print out first name, last name, middle name and initial name of 3 letter of last, first, and middle ?

    Rose Li Lee

    R L L

    I just know the basic c ++

    int main()

    string lastname, firstname, middlename;

    cin >> lastname >> firstname >> middlename;

    that easy, but what can I do if I want come out firstname, lastname, middlename and initial name?

    Thank

  2. #2
    Member
    Join Date
    Nov 2002
    Location
    Whaaaaat...........
    Posts
    44
    PHP Code:
    main()
    {
      
    /* Your Variables */
      
    int FirstName;
      
    int LastName;
      
    int MiddleName;
      
    int InitialName
      
      
    /* Your Basic Code */

      
    cout << "enter first name" << endl;
      
    cin >> FirstName;
      
    cout << "enter last name" << endl;
      
    cin >> LastName;
      
    cout << "enter middle name" << endl;
      
    cin >> MiddleName;
      
    cout << "enter initial name" << endl;
      
    cin >> InitialName;

      
    /* Show The Info */

      
    cout << " Your Name Is" << FirstName << MiddleName << LastName << InitialName << endl;

      Return 
    0
    And there ya have it, Enjoy
    A way to find answers, is to ask questions, for a question that has been asked may seem stupid for 5 minutes, but a question never asked will remain unknown forever.

  3. #3
    Member
    Join Date
    Nov 2002
    Location
    Whaaaaat...........
    Posts
    44
    Bah crap sorry I didnt read your whole post, I dont have time right now to re write another block of code, sorry just ignore my last post
    A way to find answers, is to ask questions, for a question that has been asked may seem stupid for 5 minutes, but a question never asked will remain unknown forever.

  4. #4
    Member
    Join Date
    Dec 2002
    Location
    Miami,FL
    Posts
    34
    theres only one thing u need to do....where FunyBunyFartAHH put this

    Code:
    cout << " Your Name Is" << FirstName << MiddleName << LastName << InitialName << endl;
    just change it to

    Code:
    cout << " Your Initials are " << FirstName[0] << MiddleName[0] << LastName[0] << InitialName[0] << endl;
    that will print out the first element in the name event for example
    Code:
    string myName = "RabidChimp"
    
    cout << myName[0];    //would print out "R"
    hope this helps


    oh and one more thing FunyBunyFartAHH why in the world are u using int's to store the name?????
    Death is always smiling down on us, the only thing we can do is smile back

  5. #5
    Member
    Join Date
    Nov 2002
    Location
    Whaaaaat...........
    Posts
    44
    it was night time, I was on nyquil -_-, there is your answer ^^
    A way to find answers, is to ask questions, for a question that has been asked may seem stupid for 5 minutes, but a question never asked will remain unknown forever.

  6. #6
    Member
    Join Date
    Dec 2002
    Location
    Miami,FL
    Posts
    34
    *rolling on the floor laughing*

    LOL!!

    you also forgot a semicolon and u returned 0 when u didn't specify main as int

    Nyquil must suck LOL!
    Death is always smiling down on us, the only thing we can do is smile back

  7. #7

    Thread Starter
    Member
    Join Date
    Oct 2002
    Posts
    61
    Thank FunyBunyFartAHH!
    So the output print out

    firstname
    lastname
    middlename

    and automatic come out initial first letter of firstname, lastname and middlename?


    main()
    {
    /* Your Variables */
    string FirstName;
    string LastName;
    string MiddleName;
    string InitialName,

    /* Your Basic Code */

    cout << "enter first name" << endl;
    cin >> FirstName;
    cout << "enter last name" << endl;
    cin >> LastName;
    cout << "enter middle name" << endl;
    cin >> MiddleName;
    cout << "enter initial name" << endl;
    cin >> InitialName;

    cout << " Your Initials are " << FirstName[0] << MiddleName[0] << LastName[0] << InitialName[0] << endl;

    Return 0;

  8. #8

    Thread Starter
    Member
    Join Date
    Oct 2002
    Posts
    61
    Thank RabidChimp

  9. #9
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    BTW the naked

    main()

    is more C syntax than C++ syntax. The correct declaration in C++ is

    int main()

    or

    int main(int argc, char **argv)

    and always have a

    return 0;

    at the very end of the main function.


    RabidChimp: at least FunyBuny was right with the return 0;. In C, if no return type is specified, int is assumed.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width