What did I do wrong?

#include <iostream>
#include <string> //here is the second directive to the compiler.
char middlename;
char lastname;

int main()
{ using namespace::std;
string name; //this is a declaration sentence.
cout << "What is your first name?" << endl;
cin >> name; //user designates name by typing value.
cout << "What is your middle name?" << endl;
cin >> middlename; //user designates name by typing value.
cout << "What is your last name?" << endl;
cin >> lastname;
cout << "Hello "<<name<<" "<<middlename<<" "<<lastname<<" "," "I hope you are having a good day.";
system("pause");
}

What did I do wrong? Btw: even though one line is forced back onto another line that's not what it's like on my program. my compiler told me line 15 (cout << "Hello " <<name<<....) was the problem. Please help me!
you need to initialize the variable name like you did for middlename and lastname
Your quotes are messed up around the comma.
You're missing a << and you're missing a << endl

Line 15 should be:
 
cout << "Hello "<<name<<" "<<middlename<<" "<<lastname<<", " << "I hope you are having a good day." << endl;


BTW, lastname is only a single char. You probably want to make it a string.

@sakonpure6 - No. string name is implicity initialized to an empty string.
Thanks for all your help. I understand now. You were particularly helpful AbstractionAnon. The only question I have is what do you mean make lastname a string? I typed the same for the lastname as the middle and first, or so I think......
Last edited on
1
2
char middlename;
char lastname;


Those are both single characters, not strings.
I really don't want to sound stupid, but this is my second program, and I am sad to say I don't know the difference between declaring a character, and a string. Please don't laugh.
1
2
int main()
{ using namespace::std;


This should be:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#include <iostream>
#include <string> //here is the second directive to the compiler.

using namespace std;


int main()
{ 
string  middlename;
string  lastname;


string name; //this is a declaration sentence.



Please don't laugh.


It's all right - everyone has to start somewhere.

Try to look at examples & tutorials on the web or in a book - then extend them a bit - you will be flying in no time.
I am not laughing, because I am a new here, lol
You're clever enough! go on~
Thanks for all the help. I learned alot. Kudos to theideasman.
Topic archived. No new replies allowed.