Issue with identifiers and user prompts

I am currently writing a project for college C++, and this week I am supposed to ask a customer using my application for their name, phone number, and other information. When I start creating variables (shown below), I start running into issues.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
int main()
{
	string customername;
	cout << "Enter your first and last name: ";
	cin >> customername;
	int phonenumber;
	cout << "Enter your phone number with no spaces";
	cin >> phonenumber;
	string address;
	cout << "Enter your address";
	cin >> address;
	int creditcard;
	cout << "Enter your credit card number";
	cin >> creditcard;
	string expdate;
	cout << "Enter your card expiration date as month/year";
	cin >> expdate;
	int cid;
	cout << "Enter your CID";
	cin >> cid;
	cout << customername;
	cout << phonenumber;
	cout << address;
	cout << creditcard;
	cout << expdate;
	cout << cid;
	return 0;
}


I ask the user for their name first, and on a hunch after I was done writing this part I had the system output all of the data it had stored under these variables. First of all, the program only asks me the first question - after that, it skips everything else completely and just outputs it at the end. Second, when it does output the customer name, it only outputs their first name. I'm totally lost, if anyone could help I'd really appreciate it.
You need to add some include files above main.
1
2
3
4
#include <iostream>
#include <string>

using namespace std;
I have all of them, i just didn't input them here.
on a simpler level, i'm starting by asking for a full name and trying to output it back out, and it's dropping the last name:

<code>
#include "stdafx.h"
#include <iostream>
#include <sstream>
#include <fstream>
#include <string.h>
#include <cstdlib>
#include <string>
using namespace std;

int main()
{
string customername;
cout << "Enter your first and last name:" << endl;
cin >> customername;
cout << customername;
return 0;
}
</code>

can anyone explain why this is happening? if I input John Doe it only returns with John.
and then after the above issue, if you go back to the original code in the original post, the program does not ask me for any of those outputs at all, it just blows through them and finishes.
You need to use getline. the >> operator stops reading when it encounters white space.
got it ok, thanks - now i'm trying to ask for their address - I have this:

<code>
string addpt1, addpt2, addpt3, addpt4, addpt5, addpt6, addpt7;
cout << "Enter your full address with no punctuation:" << endl;
cin >> addpt1 >> addpt2 >> addpt3 >> addpt4 >> addpt5 >> addpt6 >> addpt7;
</code>

this works if their address has seven parts (ie 123 north south court denver colorado 80018), but if the address has any more or any less parts than 7 it doesn't work - how would I make this so that it can handle any address?
Topic archived. No new replies allowed.