返回列表 發帖
本帖最後由 洪子涵 於 2019-10-19 10:47 編輯
  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.     string name[]={"遙控汽車","飛機模型","足球 ","拼圖 ","玩具槍","可愛玩偶","籃球 "};
  7.     int mn[]={450,550,325,200,660,150,380};
  8.     cout<<"智能玩具店"<<endl<<endl;
  9.     cout<<"[商品價目表]"<<endl;
  10.     int n,q,sum=0;
  11.     for(int i=0; i<7; i++)
  12.     {
  13.          cout<<"("<<i+1<<")"<<name[i]<<"\t"<<mn[i]<<"元"<<endl;
  14.     }
  15.     cout<<"(8)結帳"<<endl<<endl;
  16.     re:
  17.     cout<<"請輸入商品代碼:";
  18.     cin>>n;
  19.    
  20.     if(n>=1 && n<=7)
  21.     {
  22.         cout<<"數量:";
  23.         cin>>q;
  24.         if(q>0)
  25.         {
  26.             sum=sum+mn[n-1]*q;
  27.             goto re;
  28.         }else
  29.         {
  30.             cout<<"輸入錯誤"<<endl;
  31.             goto re;
  32.         }
  33.     }
  34.     else if(n==8)
  35.     {
  36.          goto checkout;
  37.     }else
  38.     {
  39.          cout<<"輸入錯誤"<<endl;
  40.          goto re;
  41.     }
  42.     checkout:
  43.         cout<<"總金額:"<<sum<<"元"<<endl;
  44.         
  45.    
  46.     system("pause");   
  47.     return 0;
  48. }
複製代碼

TOP

返回列表