道であれば見てのそのだけの問題次に、この
Menu list
-
food 1
food 2
food 3
-
quit (q)
のように見えます:
const int menu[]{ 10,20,30 };
int a=0, b=0, c=0;
cout << "enter your mix.(a=10,b=20 and c=30). Press other keys to sum." << endl;
char input;
cin >> input;
while (input != 'q')
{
switch (input)
{
case 'a' :a += menu[0]; break;
case 'b' :b += menu[1]; break;
case 'c' :c += menu[2]; break;
default:
cout << a << " + " << b << " + " << c <<" = "<< a + b + c << endl;
a = b = c = 0;
cout << "enter a,b,or c." << endl;
}
cin >> input;
}
結果:
enter your mix.(a=10,b=20 and c=30). Press other keys to sum.
b
b
c
c
c
7
0 + 40 + 90 = 130
enter a,b,or c.