hi everybody!!
iam taking this class c++ in summer and is really giving me a lot of problems
here is tha hw question
write a program that reads a person's name int he folowing formaty:first name , then middle name or initial, and then last name. , ur program should work the same and place a period after the middle initial even if the input did not contais a period. your program shold allow for users who give no middle name. inthat case the output, of course, contains no middle name or initial.do one with string and the other one with c-strings.
and this is what i have so far
Code:
#include <iostream>
#include <string>
using namespace std;
int main()
{
// Variable declarations
//
string first,second,third,record_name;
// strings read in
int ch; // character in input after second string
char middleInitial;
//
// Get the first two strings read in (first and middle names or
// first and last names)
cout << endl;
cout << "Please enter a Full name : ";
cin>> first >> second >> third;
record_name = third +"," + first + " " + second[0] + ".";
cout << record_name <<endl;
char letter;
cout <<"enter letter";
cin >> letter;
return 0;
}
program compiles ok when there is a name , last and initial but when there is no middle initial, doesn't , how can i get the second string to do this, sould i use the function substr or the function find with a if statement??
really confused now.....hehe any input will be apreciated!!
thanks
macedonio