-
c++ need help
Can someone help me out this program ?
I want write a program to print out first name, last name, middle name and initial name of 3 letter of last, first, and middle ?
Rose Li Lee
R L L
I just know the basic c ++
int main()
string lastname, firstname, middlename;
cin >> lastname >> firstname >> middlename;
that easy, but what can I do if I want come out firstname, lastname, middlename and initial name?
Thank
-
PHP Code:
main()
{
/* Your Variables */
int FirstName;
int LastName;
int MiddleName;
int InitialName
/* Your Basic Code */
cout << "enter first name" << endl;
cin >> FirstName;
cout << "enter last name" << endl;
cin >> LastName;
cout << "enter middle name" << endl;
cin >> MiddleName;
cout << "enter initial name" << endl;
cin >> InitialName;
/* Show The Info */
cout << " Your Name Is" << FirstName << MiddleName << LastName << InitialName << endl;
Return 0;
And there ya have it, Enjoy :)
-
Bah crap sorry I didnt read your whole post, I dont have time right now to re write another block of code, sorry :( just ignore my last post
-
theres only one thing u need to do....where FunyBunyFartAHH put this
Code:
cout << " Your Name Is" << FirstName << MiddleName << LastName << InitialName << endl;
just change it to
Code:
cout << " Your Initials are " << FirstName[0] << MiddleName[0] << LastName[0] << InitialName[0] << endl;
that will print out the first element in the name event for example
Code:
string myName = "RabidChimp"
cout << myName[0]; //would print out "R"
hope this helps:D
oh and one more thing FunyBunyFartAHH why in the world are u using int's to store the name?????:p
-
it was night time, I was on nyquil -_-, there is your answer ^^
-
*rolling on the floor laughing*
LOL!!:D
you also forgot a semicolon and u returned 0 when u didn't specify main as int
Nyquil must suck LOL!
-
Thank FunyBunyFartAHH!
So the output print out
firstname
lastname
middlename
and automatic come out initial first letter of firstname, lastname and middlename?
main()
{
/* Your Variables */
string FirstName;
string LastName;
string MiddleName;
string InitialName,
/* Your Basic Code */
cout << "enter first name" << endl;
cin >> FirstName;
cout << "enter last name" << endl;
cin >> LastName;
cout << "enter middle name" << endl;
cin >> MiddleName;
cout << "enter initial name" << endl;
cin >> InitialName;
cout << " Your Initials are " << FirstName[0] << MiddleName[0] << LastName[0] << InitialName[0] << endl;
Return 0;
-
-
BTW the naked
main()
is more C syntax than C++ syntax. The correct declaration in C++ is
int main()
or
int main(int argc, char **argv)
and always have a
return 0;
at the very end of the main function.
RabidChimp: at least FunyBuny was right with the return 0;. In C, if no return type is specified, int is assumed.