Question #99409

Write a program that reads a person's first and last names, separated by a space. Then the program outputs last name, comma, first name. End with newline.

Example output if the input is: Maya Jones
Jones, Maya

Expert's answer

#include <iostream>
#include <string>

using namespace std;

int main() {
    // Variables
    string firstName;
    string lastName;

    // Enter the first and last name
    cout << "Write first and last name\n";
    cin >> firstName >> lastName;

    // Output the result
    cout << lastName << ", " << firstName;

    return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

LATEST TUTORIALS
APPROVED BY CLIENTS