C++ and mathematical expressions

I have an practical due tomorrow and I was wondering if anyone could help me I cant seem to find the right way to start with this question, I know that I should use get line but I am not very good at it:

Write a programme that prompts the user to enter 3 first names, surnames and initials
(In that order on a single line per full name). Print the three names in the following
format: Surname, Initials, First name (Tip: Do not use >> with cin for string objects
containing spaces). The programme output should be as follows:
Please enter three full names:
Ralph Emerson W
Nelson Mandela R
Augustus de Morgan A

Formatted:
Emerson W Ralph
Mandela R Nelson
de Morgan A Augustus
How can you be good or bad at it?

std::getline(std::cin,youString);

There really isn't anything much you have to do here.
that might be the case, but I cant seem to understand how the logic of the string works. I tried doing it a coupe of times but I always seem to mess something up.
Logic? What do you mean?
I think I figured it out, can you plz check if this is correct?



#include <iostream>
#include <string>
using namespace std;

int main()

{

string str, stra, strb, strc, strd, stre, strf, strg, strh;
cout << "Please enter 1st name : ";
getline (cin,str);
cout << "Please enter 1st surname : ";
getline (cin,stra);
cout << "Please enter 1st initials : ";
getline (cin,strb);
cout << "Please enter 2nd name : ";
getline (cin,strc);
cout << "Please enter 2nd surname : ";
getline (cin,strd);
cout << "Please enter 2nd initials : ";
getline (cin,stre);
cout << "Please enter 3rd name : ";
getline (cin,strf);
cout << "Please enter 3rd surname : ";
getline (cin,strg);
cout << "Please enter 3rd initials : ";
getline (cin,strh);
cout << str << " " << strb << " " << stra << " " << ".\n" << strc << " " << strb << " " << stre << " " << ".\n" << strf << " " << strh << " " << strg << " " << ".\n";
return 0;

}
If I understood the task description, this should be correct. It would help if you'd use more meaningful names than "stra" though.
I taught so to but I was afraid I would get confused but now that I know its right I'll change it. Thanks for your help.
Your program does have a problem displaying the second name and I hope you have the commons sense not to plagiarize this example as you might have a hard time coming with an explanation why you coded this way or be hard pressed to come up with something similar in the next exercise.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
int main (void) {

    char    Entry [3][48], *Pos;
    int     I;

    for ( I = 0; I < 3; I++) {
             cout << "Name: [" << I + 1 << "]  ";
             cin.getline (Entry [I], 48); }

    // Put a bit a space between entry and display
    cout << "\n\n\n\n\n";

    // Parse the entires according to exercise specifications

    for ( I = 0; I < 3; I++ ) {
        char    *Given, *Initial;

        Pos = Entry [I];
        bool Status = false;

        while ( *Pos ) {

            if ( *Pos == ' ') {
                *Pos++ = 0;

                if ( Status == false )
                    { Given = Pos; Status = true; }
                else
                    { Initial = Pos; break; }
                }
            else
                Pos++;
            }

       // You may want to delete the part that puts a period after initial 
       // as it doesn't ask for that

       cout << Given << " " << Initial << ". " << Entry [I] << endl;
        }

    return 0;
    }


This just might give you a better idea how loops and conditionals are used to accomplish a job.
thanks it helped allot.
Topic archived. No new replies allowed.