[prog] switch statement

Kathryn Hogg kjh at flyballdogs.com
Thu Dec 16 06:12:23 EST 2004


Wolf Rising said:
> This is a program I was trying to do, I think I have most of it
> working except where default
> comes into play. If you enter an incorrect number twice, it doesn't
> really pick up on it. Any
> suggestions for how I could improve this?

What is supposed to do when you enter an incorrect product number?  It
looks to me like you should go back to switch statement.

do {
   cout << "enter product number" << endl;
   do {
      cin >> product;
      switch (product) {
         case 1: .....

         default:
             cout <<"invalid product" << endl;
             cout << "enter product number: " << endl;
         }
    } while (while product < 1 || product > 5);

    //order quantity of product desired
    cout << "Enter the quantity of this product you wish to order: ";
    //receive quantity
    cin >> quantity;

    //calculate cost
    cost = quantity * price;

    cout << "Enter the product number: ";
    cin >> product;
   }
 }

 totalSales += cost;


-- 
Kathryn
http://womensfooty.com



More information about the Programming mailing list