標題:
購物系統 (二)
[打印本頁]
作者:
tonyh
時間:
2019-3-2 10:16
標題:
購物系統 (二)
本帖最後由 tonyh 於 2019-3-2 10:19 編輯
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
cout<<"☆★☆智能玩具店☆★☆"<<endl<<endl;
cout<<"[商品價目表]"<<endl;
string a[7]={"遙控器車","飛機模型","足球 ",
"拼圖 ","玩具槍 ","可愛玩偶","籃球 "};
int price[7]={450,550,325,200,660,
150,380 };
int p,q,sum=0; //p商品代碼 q商品數量
for(int i=0;i<7;i++)
{
cout<<"("<<i+1<<")"<<a[i]<<"\t"<<price[i]<<"元"<<endl;
}
cout<<"(8)結帳"<<endl<<endl;
re:
cout<<"請輸入商品代碼: ";
cin>> p;
if(p>=1 && p<=7)
{
cout<<"數量: ";
cin>> q;
if(q>0) //數量>0
{
sum= sum+ price[p-1]*q; //計算總金額
goto re;
}else //數量<0
{
cout<<"您輸入的數量有誤!!"<<endl;
goto re;
}
}else if(p==8)
{
goto checkout;
}else
{
cout<<"您輸入的代碼有錯!!"<<endl;
goto re;
}
checkout:
cout<<"總金額: "<<sum<<"元"<<endl;
system("pause");
return 0;
}
複製代碼
作者:
田宇任
時間:
2019-3-2 11:13
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
int sum=0;
int x,y;
string s[]={"珍珠奶茶","茉莉綠茶","泡沫紅茶","菊花茶","多多綠茶","梅子可樂","檸檬愛玉"};
int m[]={50,35,20,30,35,25,45};
cout<<"☆★☆清薪飲料店☆★☆"<<endl<<endl;
cout<<"[商品價目表]"<<endl;
for(int i=0;i<7;i++)
{
cout<<"("<<i+1<<")"<<s[i]<<"\t"<<m[i]<<"元"<<endl;
}
cout<<"(8)結帳"<<endl<<endl;
while(true)
{
cout<<"請輸入商品代碼: ";
cin>>x;
if(x==8)
break;
cout<<"數量: ";
cin>>y;
sum+=m[x-1]*y;
}
cout<<endl<<"共"<<sum<<"元!"<<endl;
system("pause");
return 0;
}
複製代碼
作者:
蘇昱全
時間:
2019-3-2 11:22
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
int sum=0;
int code,qty;
string name[]={"齊爾 爆焰龍捲","卡莉 聖域福音","悟空 合金進化","夜叉 戰地之王","瑟斐斯 煉獄修羅","柯里納卡 荒漠邪翅","馬洛斯 鋼鐵戰線"};
int price[]={450,550,325,200,660,150,150,380};
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;
while(true)
{
cout<<"請輸入商品代碼:";
cin>>code;
if(code==8)
break;
cout<<"數量:";
cin>>qty;
sum+=price[code-1]*qty;
}
cout<<endl<<"總共"<<sum<<"元"<<endl;
system("pause");
return 0;
}
複製代碼
作者:
湯郡一
時間:
2019-3-2 11:33
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
int z,f,sum=0;
string x[]={"菠蘿麵包 ","小餐包(六入) ","巧克力熱壓吐司","紅豆麵包 ","桂圓麵包 ","培根玉米三明治","北歐圓法(四入)"};
int y[]={35,50,45,30,55,65,45};
cout<<"左營可口麵包店"<<endl<<endl;
cout<<"{麵包價目表]"<<endl;
for(int i=0;i<7;i++)
{
cout<<"("<<i+1<<")"<<x[i]<<"\t"<<y[i]<<"元"<<endl;
}
cout<<"(8)結帳"<<endl<<endl;
while(true)
{
cout<<"請輸入商品代碼: ";
cin>>z;
if(z==8)
break;
cout<<"數量: ";
cin>>f;
sum+=y[z-1]*f;
}
cout<<endl<<"共"<<sum<<"元!"<<endl;
system("pause");
return 0;
}
複製代碼
歡迎光臨 種子論壇 | 高雄市資訊培育協會學員討論區 (http://istak.org.tw/seed/)
Powered by Discuz! 7.2