ignore funtiction?

Discussion in 'C++' started by Luis, Jun 25, 2003.

  1. Luis

    Luis Guest

    Please help, this is due at 11:59 PM tonite. Thanks



    Write a program that reads a person's name from the keyboard in the format
    First Middle Last. It should then (1) print each of the names on a separate
    line and (2) print the person's initials on the fourth line. Assume that
    each person has exactly 3 names, that the first name begins in the first
    position on a line (there are no leading blanks) and that the names are
    separated from each other by a single blank.

    Do not use arrays in this assignment.



    SO far i gigured out only how to print out the initials, but i can't figure
    out how to get each part of a name as a seperate string. Can any one help me
    out? here is my source so far

    #include <iostream>
    #include <string>


    using namespace std;

    int main ()
    {

    char m;
    char l;
    char f;



    cin>>f;
    cin.ignore(100,' ');
    cin>>m;
    cin.ignore(100,' ');
    cin>>l;

    cout<<f<<m<<l<<endl;



    return 0;
    }
     
    Luis, Jun 25, 2003
    #1
    1. Advertising

  2. "Luis" <> wrote...
    > Please help, this is due at 11:59 PM tonite. Thanks
    >
    >
    >
    > Write a program that reads a person's name from the keyboard in the format
    > First Middle Last. It should then (1) print each of the names on a

    separate
    > line and (2) print the person's initials on the fourth line. Assume that
    > each person has exactly 3 names, that the first name begins in the first
    > position on a line (there are no leading blanks) and that the names are
    > separated from each other by a single blank.
    >
    > Do not use arrays in this assignment.
    >
    >
    >
    > SO far i gigured out only how to print out the initials, but i can't

    figure
    > out how to get each part of a name as a seperate string. Can any one help

    me
    > out? here is my source so far
    >
    > #include <iostream>
    > #include <string>
    >
    >
    > using namespace std;
    >
    > int main ()
    > {
    >
    > char m;
    > char l;
    > char f;


    Declare them as 'string'.

    >
    >
    >
    > cin>>f;
    > cin.ignore(100,' ');
    > cin>>m;
    > cin.ignore(100,' ');
    > cin>>l;


    Drop the 'ignore's.

    >
    > cout<<f<<m<<l<<endl;


    To output each of them on a separate line you need a line
    separator between them, don't you?

    Now, regarding the initials, what are they? Each initial
    is the very first character of each name, right? So, output
    the initials by outputting the very first character in each
    string.

    >
    >
    >
    > return 0;
    > }
    >
    >
    >
    >
    >
    >
     
    Victor Bazarov, Jun 25, 2003
    #2
    1. Advertising

  3. Luis

    Andre Kostur Guest

    "Luis" <> wrote in news:4jpKa.18096$Fy6.5818@sccrnsc03:

    > Please help, this is due at 11:59 PM tonite. Thanks
    >
    >
    >
    > Write a program that reads a person's name from the keyboard in the
    > format First Middle Last. It should then (1) print each of the names
    > on a separate line and (2) print the person's initials on the fourth
    > line. Assume that each person has exactly 3 names, that the first name
    > begins in the first position on a line (there are no leading blanks)
    > and that the names are separated from each other by a single blank.
    >
    > Do not use arrays in this assignment.
    >
    >
    >
    > SO far i gigured out only how to print out the initials, but i can't
    > figure out how to get each part of a name as a seperate string. Can
    > any one help me out? here is my source so far
    >
    > #include <iostream>
    > #include <string>
    >
    >
    > using namespace std;
    >
    > int main ()
    > {
    >
    > char m;
    > char l;
    > char f;
    >
    >
    >
    > cin>>f;
    > cin.ignore(100,' ');
    > cin>>m;
    > cin.ignore(100,' ');
    > cin>>l;
    >
    > cout<<f<<m<<l<<endl;
    >
    >
    >
    > return 0;
    > }


    Well..... first thing to note is that you're reading into variables of
    type 'char'. char can only hold one character. Look up a standard type
    named "std::string".
     
    Andre Kostur, Jun 25, 2003
    #3
  4. "E. Robert Tisdale" <> wrote...
    > Andre Kostur wrote:
    > > Luis wrote:
    > >
    > >>Do not use arrays in this assignment.

    > >
    > > Well..... first thing to note is that you're reading into variables of
    > > type 'char'. char can only hold one character.
    > > Look up a standard type named "std::string".

    >
    > Isn't a std::string an array?


    No, it isn't. Are you trolling again?
     
    Victor Bazarov, Jun 26, 2003
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Oleg
    Replies:
    0
    Views:
    1,214
  2. kelly
    Replies:
    1
    Views:
    2,388
    Jim Gibson
    Jan 3, 2006
  3. twahl
    Replies:
    2
    Views:
    643
    Tian Min Huang
    Jun 30, 2003
  4. Steven Lee

    PLEASE IGNORE: TESTING

    Steven Lee, Jun 30, 2003, in forum: ASP .Net
    Replies:
    1
    Views:
    378
    Jon Davis
    Jun 30, 2003
  5. Rob Meade
    Replies:
    6
    Views:
    300
    Rob Meade
    Mar 1, 2004
Loading...

Share This Page