返回列表 發帖
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
    int p,q,sum=0;
    string name[]={"笑氣    ","雄商飛彈","核彈  ","拼圖飛機","羽毛球","乒乓球","籃球    "};
    int price[]={45000,55000,32500,20000,66000,15000,38000};
    cout<<"***智能玩具店***"<<endl<<endl;
    cout<<"[商品價目表]"<<endl;
    for(int i=0; i<7; i++)
         cout<<"("<<i+1<<")"<<name[i]<<"\t"<<price[i]<<"元"<<endl;
    cout<<"(8)結帳"<<endl<<endl;
    re:
    cout<<"請輸入商品代碼: ";
    cin>>p;
    if(p==8)
    {
         goto checkout;        
    }else if(p>=1 && p<=7)
    {
        cout<<"數量: ";
        cin>>q;
        sum+=price[p-1]*q;
        goto re;
    }else
    {
        goto re;     
    }
    checkout:
    cout<<endl<<"總共"<<sum<<"元!"<<endl<<endl;         
    system("pause");
    return 0;
}

TOP

  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.     int p,q,sum=0;
  7.     string name[]={"笑氣    ","雄商飛彈","核彈  ","拼圖飛機","羽毛球","乒乓球","籃球    "};
  8.     int price[]={45000,55000,32500,20000,66000,15000,38000};
  9.     cout<<"***智能玩具店***"<<endl<<endl;
  10.     cout<<"[商品價目表]"<<endl;
  11.     for(int i=0; i<7; i++)
  12.          cout<<"("<<i+1<<")"<<name[i]<<"\t"<<price[i]<<"元"<<endl;
  13.     cout<<"(8)結帳"<<endl<<endl;
  14.     re:
  15.     cout<<"請輸入商品代碼: ";
  16.     cin>>p;
  17.     if(p==8)
  18.     {
  19.          goto checkout;        
  20.     }else if(p>=1 && p<=7)
  21.     {
  22.         cout<<"數量: ";
  23.         cin>>q;
  24.         sum+=price[p-1]*q;
  25.         goto re;
  26.     }else
  27.     {
  28.         goto re;     
  29.     }
  30.     checkout:
  31.     cout<<endl<<"總共"<<sum<<"元!"<<endl<<endl;         
  32.     system("pause");
  33.     return 0;
  34. }
複製代碼

TOP

返回列表