|
-
Feb 10th, 2003, 08:25 PM
#1
Thread Starter
Member
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
-
Feb 10th, 2003, 09:04 PM
#2
Member
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
A way to find answers, is to ask questions, for a question that has been asked may seem stupid for 5 minutes, but a question never asked will remain unknown forever.
-
Feb 10th, 2003, 09:05 PM
#3
Member
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
A way to find answers, is to ask questions, for a question that has been asked may seem stupid for 5 minutes, but a question never asked will remain unknown forever.
-
Feb 11th, 2003, 12:48 PM
#4
Member
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
oh and one more thing FunyBunyFartAHH why in the world are u using int's to store the name?????
Death is always smiling down on us, the only thing we can do is smile back
-
Feb 11th, 2003, 03:03 PM
#5
Member
it was night time, I was on nyquil -_-, there is your answer ^^
A way to find answers, is to ask questions, for a question that has been asked may seem stupid for 5 minutes, but a question never asked will remain unknown forever.
-
Feb 11th, 2003, 03:31 PM
#6
Member
*rolling on the floor laughing*
LOL!!
you also forgot a semicolon and u returned 0 when u didn't specify main as int
Nyquil must suck LOL!
Death is always smiling down on us, the only thing we can do is smile back
-
Feb 11th, 2003, 07:23 PM
#7
Thread Starter
Member
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;
-
Feb 11th, 2003, 09:35 PM
#8
Thread Starter
Member
Thank RabidChimp
-
Feb 12th, 2003, 07:30 PM
#9
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.
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|