Sign in to follow this  

Cin Help Needed!

This topic is 4225 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello, I've been focusing on school work for the past week or two, so i havent been able to program for the past week or so. I started making this little program, just to get a little practice, and it doesnt seem to work right. It takes the first letter off every input the user enters, which throws off everything. Any help is appreciated.
//////////////////////////////////////////////////////////////////////////////////
// ASK FOR CUSTOMERS NAME 
//////////////////////////////////////////////////////////////////////////////////
	
	string custOrder;
	string custName;
	string custId;

		cout << "\t\tHello, What is your Name? ";
			cin.ignore();
				getline(cin,custName);

	system("CLS");

//////////////////////////////////////////////////////////////////////////////////
// ASKS HOW MUCH GAS THEIR SPACECRAFT NEEDS AND FOR ID
//////////////////////////////////////////////////////////////////////////////////

		cout << "Would you like a Full Tank for your Space Cruiser X, " << custName << "? ";
			cin.ignore();
				getline(cin,custOrder);

//////////////////////////////////////////////////////////////////////////////////
// KEY TESTING
//////////////////////////////////////////////////////////////////////////////////
	if(custOrder[0] == 'y')
		cout << "1\n\n";
			if(custOrder[0] != 'y')
				cout << "0\n\n";

	cout << "\n\nDo you Have your Space ID? ";
		
	if(custId[0] == 'y')
		cout << "\n\nOk, your car will be ready in 1 sec.\nThanks for Choosing Sapce Filler!\n\n";
			if(custId[0] != 'y')
				cout << "\n\nSorry, I cannot help you then, its store Policy.\n\n";

///////////////////////////////////////////////////////////////////////////////////
// EXIT
///////////////////////////////////////////////////////////////////////////////////
	system("PAUSE");
	return 0;

Share this post


Link to post
Share on other sites
ignore() tells the program to ignore a character of input. So, you're basically telling the program to ignore a character of input and then get the rest of what the user input.

So, get rid of the ignore(). You probably won't need it at all because getline grabs the newline as well.

Share this post


Link to post
Share on other sites

This topic is 4225 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this