Well, I'm stumped again. This is a pretty simple problem. Get info from user for 3 products, sort them by price and display in a table. So, I have included the string library, and I'm using getline(cin, userString, '\n') to get the description from the user. It works fine the first time through, but on second and third times it does the cout right before the getline prompt then skips to the next cout(for serial number). It's not wrong syntaxually (sp?), I'm just wondering if there's something I'm missing or if it's my compiler. Here's the code
Code:
int main()
{
string userString1, userString2, userString3;
int serial1, serial2, serial3;
double price1 = 0, price2 = 0, price3 = 0;
char yesNo = 'n';
cout << "Please enter information:" << endl;
cout << "Brief Description: ";
getline(cin, userString1, '\n'); //works here
cout << "Serial number: ";
cin >> serial1;
cout << "Price: $";
cin >> price1;
cout << "Please enter information:" << endl;
cout << "Brief Description: ";
getline(cin, userString2, '\n'); //doesn't work here
cout << "Serial number: ";
cin >> serial2;
cout << "Price: $";
cin >> price2;
cout << "Please enter information:" << endl;
cout << "Brief Description: ";
getline(cin, userString3, '\n');
cout << "Serial number: ";
cin >> serial3;
cout << "Price: $";
cin >> price3;
cout << "Thank you." << endl;
cout << "Ready to display table(Y or N)? ";
cin >> yesNo;
Sorter(price1, serial1, userString1,
price2, serial2, userString2,
price3, serial3, userString3);
cin >> yesNo;
return(0);
}
can anybody help? thanks!