返回列表 發帖
  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.     "玩具槍  ","可愛玩偶","籃球    "};
  8.    
  9.     int price[]={450,550,325,200,660,150,380};
  10.     cout<<"☆★☆智能玩具店☆★☆"<<endl<<endl;
  11.     cout<<"[商品價目表]"<<endl;
  12.     int p,q,sum=0;
  13.     for(int i=0; i<7; i++)
  14.     {
  15.          cout<<"("<<i+1<<")"<<name[i]<<"\t"<<price[i]<<"元"<<endl;
  16.     }
  17.     cout<<"(8)結帳"<<endl<<endl;
  18.     re:
  19.     cout<<"請輸入商品代碼:";
  20.     cin>>p;
  21.    
  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.         }else
  31.         {
  32.             cout<<"輸入錯誤!!!"<<endl;
  33.             goto re;
  34.         }
  35.     }
  36.     else if(p==8)
  37.     {
  38.          goto checkout;
  39.     }else
  40.     {
  41.          cout<<"輸入錯誤!!!"<<endl;
  42.          goto re;
  43.     }
  44.     checkout:
  45.         cout<<"總金額:"<<sum<<"元"<<endl;
  46.         
  47.    
  48.     system("pause");   
  49.     return 0;
  50. }
複製代碼

TOP

返回列表