hello all,
I'm taking a C++ class at my local community college. A project that was assigned was to make a menu program. I am about 90% done (I think), when I ran into this issue: when making a selection, the program doesn't know how to handle decimal numbers. The output asks for a quantity, but there is no input, then it displays the menu again. (EDIT: when a negative decimal number is inputted, it goes into an infinite loop) What I want it to display is "That is not a valid option." I think it might have something to do with the parameter I have set for my [while] command. Any thoughts?
Example run:
(correct)
Welcome to spendCo.Please make a selection.
Enter 1 for Coffee - $12.95
Enter 2 for Tea - $ 9.95
Enter 3 for Sugar - $ 1.50
Enter 4 for Salt - $ 2.25
Enter 5 for Milk - $ 3.00
Enter 6 to see what you owe
Enter 0 when you are done4
Please ender desired quantity
2(incorrect)
Please make a selection.Enter 1 for Coffee - $12.95
Enter 2 for Tea - $ 9.95
Enter 3 for Sugar - $ 1.50
Enter 4 for Salt - $ 2.25
Enter 5 for Milk - $ 3.00
Enter 6 to see what you owe
Enter 0 when you are done2.3
Please enter desired quantityPlease make a selection.
Enter 1 for Coffee - $12.95
Enter 2 for Tea - $ 9.95
Enter 3 for Sugar - $ 1.50
Enter 4 for Salt - $ 2.25
Enter 5 for Milk - $ 3.00
Enter 6 to see what you owe
Enter 0 when you are done
Here it is:
/******************************************************************************
*Written by Aaron Wells Project 02 3/03/10
******************************************************************************/
#include <iostream>
#include <iomanip>
using namespace std;
/******************************************************************************
* Note:
*
******************************************************************************/
void main()
{
int choice;
double qty, total = 0, total_tax;
cout.setf(ios::fixed);
cout.setf(ios::showpoint);
cout.precision(2);
cout << "Welcome to spendCo." << endl;
do
{
cout << "\nPlease make a selection." << endl;
cout << "\nEnter 1 for Coffee - $12.95";
cout << "\nEnter 2 for Tea - $ 9.95";
cout << "\nEnter 3 for Sugar - $ 1.50";
cout << "\nEnter 4 for Salt - $ 2.25";
cout << "\nEnter 5 for Milk - $ 3.00";
cout << "\nEnter 6 to see what you owe";
cout << "\nEnter 0 when you are done\n" << endl;
cin >> choice;
switch (choice)
{
case 0:
total_tax = total + total * .06;
cout << "Proceeding to checkout...\n" << endl
<< "Your total is: $" << total << endl
<< "Your total after tax is: $" << total_tax << endl
<< "Thank you, come again." << endl;
break;
case 1:
cout << "Please enter desired quantity" << endl;
cin >> qty;
total = total + 12.95 * qty;
break;
case 2:
cout << "Please enter desired quantity" << endl;
cin >> qty;
total = total + 9.95 * qty;
break;
case 3:
cout << "Please ender desired quantity" << endl;
cin >> qty;
total = total + 1.50 * qty;
break;
case 4:
cout << "Please ender desired quantity" << endl;
cin >> qty;
total = total + 2.25 * qty;
break;
case 5:
cout << "Please ender desired quantity" << endl;
cin >> qty;
total = total + 3.00 * qty;
break;
case 6:
cout << total << endl;
break;
default:
cout << "That is not a valid option" << endl;
}
}while (choice != 0);
}