Please help, this is due at 11:59 PM tonite. Thanks
Write a program that reads a person's name from the keyboard in the format
First Middle Last. It should then (1) print each of the names on a separate
line and (2) print the person's initials on the fourth line. Assume that
each person has exactly 3 names, that the first name begins in the first
position on a line (there are no leading blanks) and that the names are
separated from each other by a single blank.
Do not use arrays in this assignment.
SO far i gigured out only how to print out the initials, but i can't figure
out how to get each part of a name as a seperate string. Can any one help me
out? here is my source so far
#include <iostream>
#include <string>
using namespace std;
int main ()
{
char m;
char l;
char f;
cin>>f;
cin.ignore(100,' ');
cin>>m;
cin.ignore(100,' ');
cin>>l;
cout<<f<<m<<l<<endl;
return 0;
} 5 7823
"Luis" <ki***@attbi.com> wrote... Please help, this is due at 11:59 PM tonite. Thanks Write a program that reads a person's name from the keyboard in the format First Middle Last. It should then (1) print each of the names on a
separate line and (2) print the person's initials on the fourth line. Assume that each person has exactly 3 names, that the first name begins in the first position on a line (there are no leading blanks) and that the names are separated from each other by a single blank.
Do not use arrays in this assignment. SO far i gigured out only how to print out the initials, but i can't
figure out how to get each part of a name as a seperate string. Can any one help
me out? here is my source so far
#include <iostream> #include <string>
using namespace std;
int main () {
char m; char l; char f;
Declare them as 'string'.
cin>>f; cin.ignore(100,' '); cin>>m; cin.ignore(100,' '); cin>>l;
Drop the 'ignore's. cout<<f<<m<<l<<endl;
To output each of them on a separate line you need a line
separator between them, don't you?
Now, regarding the initials, what are they? Each initial
is the very first character of each name, right? So, output
the initials by outputting the very first character in each
string.
return 0; }
"Luis" <ki***@attbi.com> wrote in news:4jpKa.18096$Fy6.5818@sccrnsc03: Please help, this is due at 11:59 PM tonite. Thanks Write a program that reads a person's name from the keyboard in the format First Middle Last. It should then (1) print each of the names on a separate line and (2) print the person's initials on the fourth line. Assume that each person has exactly 3 names, that the first name begins in the first position on a line (there are no leading blanks) and that the names are separated from each other by a single blank.
Do not use arrays in this assignment. SO far i gigured out only how to print out the initials, but i can't figure out how to get each part of a name as a seperate string. Can any one help me out? here is my source so far
#include <iostream> #include <string>
using namespace std;
int main () {
char m; char l; char f; cin>>f; cin.ignore(100,' '); cin>>m; cin.ignore(100,' '); cin>>l;
cout<<f<<m<<l<<endl; return 0; }
Well..... first thing to note is that you're reading into variables of
type 'char'. char can only hold one character. Look up a standard type
named "std::string".
"E. Robert Tisdale" <E.**************@jpl.nasa.gov> wrote... Andre Kostur wrote: Luis wrote:
Do not use arrays in this assignment.
Well..... first thing to note is that you're reading into variables of type 'char'. char can only hold one character. Look up a standard type named "std::string".
Isn't a std::string an array?
No, it isn't. Are you trolling again?
Ok The way to do it is:
#include <iostream> // for cout, cin, endl functions
#include <string> // to make variables called strings
using namespace std; // using namespaces
int main() // the main function
{ // open the main function
string f; // create a string variable called f (first name)
string m; // create a string variable called m (middle name)
string l; // create a string variable called l (last name)
cin>>f; cin.ignore(0,' '); // input first name, then ends after the " " (space)
cin>>m; cin.ignore(0,' '); // input first name, then ends after the " " (space)
cin>>l; cin.ignore(0,' '); // input last name, hit enter.
cout<<f<<endl<<m<<endl<<l<<endl; // output first name, next line, middle name, next line, last name, next line.
system("pause"); // for windows if you want to pause the programme.
/* cin.get(); */ // remove the /**/ comments from it if you are not using windows and need to pause the programme to view it.
} // end the main function
here's the solution to your problem.
#include <iostream>
#include <string>
using namespace std;
int main()
{
string fi;
string mi;
string last;
cin >> fi >> mi >> last;
cout << fi << endl
<< mi << endl
<< last << endl;
cout << fi.substr(0,1);
cout << mi.substr(0,1);
cout << last.substr(0,1) << endl;
return 0;
}
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Thomas Müller |
last post by:
Hello!
Running my uploadscript on old server, php4.1.2 ignore aborted
fileuploads.
Now, the same script on new server doesn't ignore broken uploads.
If anybody make a upload and abort this the...
|
by: Rob Meade |
last post by:
Lo all,
I was just running through some code I was writing for a site and when it
came to the 'exact phrase' search type I wasn't sure whether that should run
through and ignore the words in the...
|
by: Thomas Bartkus |
last post by:
The meaning of REPLACE INTO is clear to me.
IF the new record presents new key values, then it is inserted as a new
record.
IF the new record has key values that match a pre-existing record, then...
|
by: Chris Mantoulidis |
last post by:
Let's say I have this:
std::string s1;
std::cin >> s1;
This will read s1 from cin until it finds a space (or a newline,
whichever comes first).
Okay this works. But when I want to continue...
|
by: windandwaves |
last post by:
Are you allowed to use the following syntax in Mysql 4.0.17-nt :
INSERT DELAYED IGNORE INTO `mytable` ( `ID` , `A` , `B` ) VALUES
("'.session_id().'", "2", ROUND(NOW()/10000) );
I am...
|
by: FrancisC |
last post by:
#include <stdio.h>
int file_copy( char *oldname, char *newname );
int main()
{
char source, destination;
printf("\nEnter source file: ");
|
by: Jackson Miller |
last post by:
I notice that postgres does not support IGNORE.
I am currently migrating an app from a MySQL datastore to Postgres, and I
would really like to use IGNORE.
I am curious if there is a...
|
by: alw0015 |
last post by:
I'm working on a piece of code that reads in a time from the user.
This time value consists of 3 separate inputs:
1 integer representing hours
1 char representing the ":"
1 integer...
|
by: sandy |
last post by:
I seem to ALWAYS need to use cin.ignore in my programs (console apps
using Dev C++ for a University course).
The problem is that if I don't ignore ENOUGH characters then it's like
not having the...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM).
In this month's session, the creator of the excellent VBE...
|
by: DolphinDB |
last post by:
Tired of spending countless mintues downsampling your data? Look no further!
In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
|
by: Aftab Ahmad |
last post by:
Hello Experts!
I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
|
by: Aftab Ahmad |
last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below.
Dim IE As Object
Set IE =...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: marcoviolo |
last post by:
Dear all,
I would like to implement on my worksheet an vlookup dynamic , that consider a change of pivot excel via win32com, from an external excel (without open it) and save the new file into a...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: ArrayDB |
last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
|
by: PapaRatzi |
last post by:
Hello,
I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
| |