gha890826

大一期中考-3

Apr 18th, 2020 (edited)
414
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.06 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main()
  5. {
  6.     char again = 'y' ;
  7.     int food;
  8.     int price;
  9.     int ctrlfood = 0;
  10.    
  11.     while (again == 'Y' || again=='y')
  12.     {
  13.        
  14.         cout << "1.大麥克\t$109\n2.麥香雞\t$89\n3.炸雞餐\t$119\n4.雙層牛肉堡\t$129" << endl;
  15.         while (ctrlfood == 0)
  16.         {
  17.             cout << "請輸入你想點的:";
  18.             cin >> food;
  19.             cout << endl;
  20.  
  21.  
  22.             switch (food)
  23.             {
  24.             case 1:
  25.                 ctrlfood = 1;
  26.                 price = 109;  
  27.                 cout << "你點的餐價格為$" << price << endl;
  28.                 break;
  29.             case 2:
  30.                 ctrlfood = 1;
  31.                 price = 89;
  32.                 cout << "你點的餐價格為$" << price << endl;
  33.                 break;
  34.             case 3:
  35.                 ctrlfood = 1;
  36.                 price = 119;
  37.                 cout << "你點的餐價格為$" << price << endl;
  38.                 break;
  39.             case 4:
  40.                 ctrlfood = 1;
  41.                 price = 129;
  42.                 cout << "你點的餐價格為$" << price << endl;
  43.                 break;
  44.             default:
  45.                 ctrlfood = 0;
  46.                 cout << "你不會點餐喔" << endl;  
  47.             }
  48.  
  49.             cout << endl;
  50.         }
  51.         cout << endl;
  52.         cout << "請問還要繼續點餐嗎(Y/N)?";
  53.         cin >> again;
  54.     }
  55.     return 0;
  56. }
Add Comment
Please, Sign In to add comment