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

TOP

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

TOP

返回列表