Simple array

I'm trying to create an array that will allow the user to input the first name and last name and then display the last name first. I wasn't able to find a similar question.

here is what I have so far...

#include <iostream>

using namespace std;

int main()
{
char fname[25];
char lname[35];

cout << "Enter your First Name" << endl;
cin >> fname;

cout << "Your first name is " << fname <<endl;

cout << "Enter your last name" <<endl;
cin >> lname;

cout << "Your last name is " << lname << endl;

cout << "Most directories would list your name as " << lname, fname << endl;


return 0;
}
1. fname/lname should look like this: string fname,lname; and you need to include <string>
2. When printing, it should be lname << fname
When I use:

#include <iostream>

using namespace std;

int main()
{
char fname[30];
char lname[30];

cout << "Enter your First Name" << endl;
cin >> fname;

cout << "Your first name is " << fname <<endl;

cout << "Enter your last name" <<endl;
cin >> lname;

cout << "Your last name is " << lname << endl;

cout << "Most directories would list your name as " << lname "," << fname << endl;


return 0;
}

everything works fine except for the last line gives me an error: "Expected ';' before string constant"
cout << "Most directories would list your name as " << lname "," << fname << endl;

should be

cout << "Most directories would list your name as " << lname << "," << fname << endl;
Topic archived. No new replies allowed.