program help!!!

Write your question here.
Hey guys very new to C ++and i am working on a program involving online purchase. when i run the program multiple text lines come up at once. I need help the homework is due soon!!!
[code]
#include <iostream>
#include <string>
using namespace std;
//homework 2
int main()
{
string name, address, city, state, zip, item;
double cost,totalcost, beforetax, tax, shipping;
int numberofitems;
cout<< "Enter Your first and last name " << endl;
cin>> name;

cout<<"Enter your address" << endl;
cin>> address;

cout<<"Enter your zip code " << endl;
cin>>zip;

cout<< "Enter your city " << endl;
cin>> city;

cout<<"Enter your state "<< endl;
cin>>state;

cout<< "Items you wish to purchase " << endl;
cin>>item;

cout<< "Enter the cost of the items " << endl;
cin>>cost;

cout<< "Enter the number of items you are purchasing " << endl;
cin>>numberofitems;

beforetax= cost*numberofitems;
tax=beforetax*.07;
shipping= beforetax*.01;
totalcost= shipping+tax+beforetax;
cout<< "Ship to:"<< endl;
cout<<name;
cout<<address;
cout<<city<<state<<zip<<endl;

cout<<"Item:"<<item<<endl;

cout<<"Item price:"<<cost<<endl;

cout<<"Quanity:"<<numberofitems<<endl;

cout<<"Total:"<<beforetax<<endl;

cout<<"Tax:"<<tax<<endl;

cout<<"Shipping:"<<shipping<<endl;

cout<<"Total Due:"<<totalcost<<endl;

system ("pause");
return 0;
}
Use std::getline() to read in a complete line which may contain spaces.

1
2
3
4
cout << "Enter Your first and last name " << endl;
//cin>> name;
getline( cin, name ) ; 
// and so on for input of all the other strings 


http://www.cplusplus.com/reference/string/string/getline/
Last edited on
Topic archived. No new replies allowed.