I'm using NetBeans 6.8
I'm trying to create a program for a class but on line 32, the getline(cin,title) statement does not work. When I placed it on a higher line it worked just fine but on 33 down it is completely ignored. I need it on that line but I'm at a loss on what to do.
/*Cashier Module for Serendipity Booksellers
Author: Robert Boesz
File created on: February 01,2010
Last Modified on: February 03, 2010
*/
#include <iostream>
#include <string>
#include <iomanip>
using namespace std;
int main()
{
const double TAX_RATE=0.06;
int qty;
double price,
booktotal,
subtotal,
tax,
fulltotal;
string date, //Designed to hold 8 characters (MM/DD/YY)
isbn;
string title;
cout<<"Serendipity Booksellers\n";
cout<<"Cashier Module\n\n";
cout<<"Date: ";
cin>>date;
cout<<"Quantity of Book: ";
cin>>qty;
29 cout<<"ISBN: ";
30 cin>>isbn;
31 cout<<"Title: ";
32 getline(cin, title ); /*Error: cannot use getline past line 33
* properly. Check on other PCs*/
cout<<"\nPrice: ";
cin>>price;
//Calculate the merchandise total, subtotal, tax, and fulltotal
booktotal = qty * price;
subtotal = booktotal;
tax = subtotal * TAX_RATE;
fulltotal = subtotal + tax;
cout<<"\nSerendipity Booksellers\n\n";
cout<<"Date: "<<date<<"\n\n";
cout<<"Qty ISBN Title Price Total\n";
cout<<"______________________________________________________________\n";
cout<<setw(5)<<left<<qty;
cout<<setw(14)<<left<<isbn;
cout<<setw(24)<<left<<title;
cout<<" $"<<fixed<<setprecision(2)<<setw(6)<<right<<price;
cout<<" $"<<setw(6)<<right<<booktotal;
cout<<endl<<endl;
cout<<" Subtotal $";
cout<<setw(6)<<right<<subtotal<<endl;
cout<<" Tax $";
cout<<setw(6)<<right<<tax<<endl;
cout<<" Total $";
cout<<setw(6)<<right<<fulltotal<<endl<<endl;
cout<<"Thank You For Shopping Serendipity!\n";
return 0;
}
What the heck is that supposed to mean?
That line works just fine when I placed it on a higher position.
I need to have the getline() on there so I may enter a string with spaces.
I fixed the problem.
The newline character in the previous statement was in the keyboard buffer and getline() was registering that.
All I needed to do is use cin.ignore() before getline to stop it.