0

Im trying to put a while loop in here and when i do i get tons of errors. but when i run it with out the while loop it works.

this program inputs the first and last name and puts it as last, first.
and uses strings for that and vector to store the name so u can do as many as u want.

need help or tips to tell me wats wrong with wat i got.

#include<iostream>
#include<string>
#include <vector>
using namespace std;
int main()
{
	string firstName, lastName, lastFirst;
	vector<string> name;
	cout << "Enter your first name: \n";
	getline(cin, firstName);
	while (firstName != 0)
	{
		cout << "Enter your last name: \n";
		getline(cin, lastName);
		lastFirst = lastName + ", "+ firstName;
		cout << lastFirst<<endl;

		
		name.push_back(lastFirst);
		cout<< lastFirst<< " added. ";
		cout << "name.size( ) = " << name.size( ) << endl;
		cin >> lastFirst;
		cout << "Enter your first name: \n";
		getline(cin, firstName);
	}	
		cout << "you entered:\n";
		for (unsigned int i = 0; i < name.size( ); i++)
			cout<<name[i] << endl;
		cout<<endl;
		system("pause");

	return 0;
}
2
Contributors
1
Reply
2
Views
9 Years
Discussion Span
Last Post by Ancient Dragon
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.