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

TOP

返回列表