xJohn - 1 year ago 157
C++ Question

# Coffee Ordering System using switch statement

Good Day! I'm trying to make a coffee ordering station using switch statement. But I'm having a hard time figuring out how to make multiple computation under 1 case statement. I don't know if it is possible though.Also, any size that I input, I always get the same total amount. Thanks for your help.

Here's my main code.

``````#include<iostream>
using namespace std;
int main()
{
int q, s, a;
int js=145, jv=165, jg=185, os=130, ov=160, og=175, bs=80, bv=120,bg=150, cs=130, cv=150, cg=185;
char d;

cout <<"[J] Java Chips (Small 145) (Venti 165) (Grande 185)" <<endl;
cout <<"[O] Oreo Cookies & Cream (Small 130) (Venti 160) (Grande 175)" <<endl;
cout <<"[B] Brewed Coffee (Small 80) (Venti 120) (Grande 150)" <<endl;
cout <<"[C] Caramel Macchiato (Small 130) (Venti 150) (Grande 185)" <<endl <<endl;
cout <<"Enter choice: ";
cin >>d;

switch(d){

case 'J':
case 'j':
cout <<"Enter Quantity: ";
cin >>q;
cout <<"Enter Size: ";
cin >>s;
a = q * js;
a = q * jv;
a = q * jg;

cout <<"The total amount of your order is: " <<a <<endl;
break;

case 'O':
case 'o':
cout <<"Enter Quantity: ";
cin >>q;
cout <<"Enter Size: ";
cin >>s;
a = q * os;
a = q * ov;
a = q * og;
cout <<"The total amount of your order is: " <<a <<endl;
break;

case 'B':
case 'b':
cout <<"Enter Quantity: ";
cin >>q;
cout <<"Enter Size: ";
cin >>s;
a = q * bs;
a = q * bv;
a = q * bg;
cout <<"The total amount of your order is: " <<a <<endl;
break;

case 'C':
case 'c':
cout <<"Enter Quantity: ";
cin >>q;
cout <<"Enter Size: ";
cin >>s;
a = q * cs;
a = q * cv;
a = q * cg;
cout <<"The total amount of your order is: " <<a <<endl;
break;

default:
}
return 0;
}
``````

You want to get item quantity and item price. Then multiply quantity by price:

``````case 'j':
cout << "Enter Quantity: ";
cin >> q;
if (q == 0)
{
cout << "Quantity was zero\n";
break;
}

cout << "Enter Size: (valid sizes: 1, 2, 3)";
cin >> s;
a = 0;
if (s == 1) a = q * js;
else if (s == 2) a = q * jv;
else if (s == 3) a = q * jg;
else cout << "You entered invalid size. Size should be 1, 2, or 3\n";

if (a != 0)
cout << "The total amount of your order is: " << a << endl;

break;
``````
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download