My program does not take input.
It is not the case of String, I am facing problem in cin operator, so I can't understand the output of the program. Please give me reason and its accurate solution.
struct Product
{
int code;
string description;
char packaging;
float price;
float discount;
};
int main()
{
Product p;
cout << "\nEnter a code of a product:\t";
cin >> p.code;
cout << "\nEnter the description of a product:\t";
getline(cin, p.description);
cin.ignore();
cout << "\nPress:";
cout << "\n\t'L' or 'l' for large";
cout << "\n\t'M' or 'm' for medium";
cout << "\n\t'S' or 's' for small";
Error
cout << "\n\nChoose your package from the list above:\t";
cin >> p.packaging;
Error
switch (p.packaging)
{
case 'L':
case 'l':
p.price = 50000;
cout << "\nThe price of a product:\t$" << p.price;
break;
case 'M':
case 'm':
p.price = 25000;
cout << "\nThe price of a product:\t$" << p.price;
break;
case 'S':
case 's':
p.price = 12500;
cout << "\nThe price of a product:\t$" << p.price;
break;
default:
cout << "\nYou entered wrong";
}
p.discount = 0.02;
cout << "\nDISCOUNT:\t" << p.discount;
double deductedPrice;
deductedPrice = p.price * p.discount;
p.price = p.price - deductedPrice;
cout << "\nDiscounted price:\t" << p.price;
cout << "\n\n\n\n\n";
system("pause");
return 0;
}
I have searched from the internet but I can't get any solution which satisfies me.