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

TOP

返回列表