Image

Imageex_skratchg wrote in Imagecpp

I know this is a question many of you will laugh at but I am dying. :( I know how to code in vb but not c++. I am in class for c++ and I don't even have my book to look up this stuff because of class switching and the book being out. So, I feel pretty much screwed. Anyhow, I have two projects due at midnight tonight and I have no idea what I am doing wrong on this first project. If you could take a look at my code and help me get in the right direction that would be awesome. my code is not out putting the first name and i am pretty confused on how to finish the project after this point anyway, I have no idea how to cin a "," after the last name or remove it on output. After namespace is the project i have to do.

#include < string>
#include < iostream>


using namespace std;

//1. Write an interactive C++ program that inputs a name
//from the user in the format of:
//last, first middle
//The program then should output the name in the format of:
//first middle last
// the program will have to use string operations to remove the comma
//from the end of the last name. Be sure to use proper formatting and
//appropriate comments in your code. The input should have an appropriate prompt
//and the output should be labeled clearly and neatly.

#include
#include


using namespace std;

//1. Write an interactive C++ program that inputs a name
//from the user in the format of:
//last, first middle
//The program then should output the name in the format of:
//first middle last
// the program will have to use string operations to remove the comma
//from the end of the last name. Be sure to use proper formatting and
//appropriate comments in your code. The input should have an appropriate prompt
//and the output should be labeled clearly and neatly.

main()
{


string first, middle, last, name;

cout << "Please enter your name as Last, First Middle: ";
//inputs user info
getline(cin,name);
last = name;
//finds location of the whitespace
int location = name.find(' ') -1;
//locates the first name
first = &name[location + 2];
last.erase(location);
//finds location of the 2nd whitespace
location = first.find(' ');
first.erase(location);
//finds the middle name
middle = &first[location + 1];

cout << "Your name is: " << first << ' ' << middle << ' ' << last << '\n';


return 0;
}

edit: i figured it all out