標題:
[隨堂測驗] 購物系統 (四)
[打印本頁]
作者:
tonyh
時間:
2019-3-9 10:12
標題:
[隨堂測驗] 購物系統 (四)
新增 "1-正確無誤 2-重新選購" 的選單,
讓使用者在準備結帳時還能反悔, 譬如錢帶不夠.
確定結帳後, 銜接自動找零系統.
本帖隱藏的內容需要回復才可以瀏覽
作者:
湯郡一
時間:
2019-3-9 11:46
本帖最後由 湯郡一 於 2019-3-9 11:47 編輯
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
re:
int z,f,sum=0;
int option,pay,money;
string x[]={"菠蘿麵包 ","小餐\包(六入) ","巧克力熱壓吐司","紅豆麵包 ","桂圓麵包 ","培根玉米三明治","北歐圓法(四入) "};
int y[]={35,50,45,30,55,65,45};
int count[]={0,0,0,0,0,0,0};
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<1 || z>8)
{
cout<<"輸入錯誤"<<endl;
continue;
}
if(z==8)
break;
cout<<"數量: ";
cin>>f;
if(f<1 || f>999)
{
cout<<"超過"<<endl;
continue;
}
count[z-1]+=f;
sum+=y[z-1]*f;
}
cout<<"[購物清單]"<<endl;
cout<<"---------------------"<<endl;
for(int i=0;i<7;i++)
{
if (count[i]!=0 )
cout<<x[i]<<"\t"<<y[i]<<"*"<<count[i]<<endl;
}
cout<<"---------------------"<<endl;
cout<<endl<<"共"<<sum<<"元!"<<endl;
re2:
cout<<"1=正確無誤 2=重新選購";
cin>>option;
if(option==1)
{
re3:
cout<<"請付帳:";
cin>>pay;
money=pay-sum;
if(money<0)
{
cout<<"錢不夠,還差"<<-money<<"元"<<endl;
goto re3;
}else if(money==0)
{
cout<<"銘謝惠顧!!"<<endl;
}else
{
cout<<"找您"<<money<<"元"<<endl;
if(money>=500)
{
cout<<"500元"<<money/500<<"張"<<endl;
money%=500;
}
if(money>=100)
{
cout<<"100元"<<money/100<<"張"<<endl;
money%=100;
}
if(money>=50)
{
cout<<"50元"<<money/50<<"個"<<endl;
money%=50;
}
if(money>=10)
{
cout<<"10元"<<money/10<<"個"<<endl;
money%=10;
}
if(money>=5)
{
cout<<"5元"<<money/5<<"個"<<endl;
money%=5;
}
if(money>=1)
{
cout<<"1元"<<money/1<<"個"<<endl;
money%=1;
}
}
}else if(option==2)
{
goto re;
}else
{
cout<<"輸入錯誤"<<endl;
goto re2;
}
system("pause");
return 0;
}
複製代碼
作者:
蘇昱全
時間:
2019-3-9 11:56
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
re:
int sum=0;
int code,qty,option,money,pay;
string name[]={"齊爾 爆焰龍捲","卡莉 聖域福音","悟空 合金進化","夜叉 戰地之王","瑟斐斯 煉獄修羅","柯里納卡 荒漠邪翅","馬洛斯 鋼鐵戰線"};
int price[]={15,20,24,18,30,12,60,2000};
int count[]={0,0,0,0,0,0,0};
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<1 || code>8)
{
cout<<"輸入錯誤!"<<endl;
continue;
}
if(code==8)
break;
cout<<"數量:";
cin>>qty;
if(qty<1 || qty>999)
{
cout<<"輸入錯誤!"<<endl;
continue;
}
count[code-1]+=qty;
sum+=price[code-1]*qty;
}
cout<<"[購物清單]"<<endl;
cout<<"------------------------"<<endl;
for(int j=0;j<7;j++)
{
if(count[j]!=0)
{
cout<<name[j]<<"\t"<<price[j]<<"元 *"<<count[j]<<"個"<<endl;
}
}
cout<<"------------------------"<<endl;
cout<<endl<<"總共"<<sum<<"元"<<endl<<endl;
re2:
cout<<"1-正確無誤 2-重新選購";
cin>>option;
cout<<endl;
if(option==1)
{
re3:
cout<<"請付帳";
cin>>pay;
money=pay-sum;
if(money>0)
{
cout<<"找您"<<money<<"元!"<<endl;
if(money>=500)
{
cout<<"五百元鈔票"<<money/500<<"張"<<endl;
money=money%500;
}
if(money>=100)
{
cout<<"一百元鈔票"<<money/100<<"張"<<endl;
money=money%100;
}
if(money>=50)
{
cout<<"五十元硬幣"<<money/50<<"枚"<<endl;
money=money%50;
}
if(money>=10)
{
cout<<"十元硬幣"<<money/10<<"枚"<<endl;
money=money%10;
}
if(money>=1)
{
cout<<"一元硬幣"<<money/1<<"枚"<<endl;
}
}
else if(money==0)
{
cout<<"銘謝惠顧!"<<endl;
}else
{
cout<<"您付的錢不夠,還差"<<money<<"元"<<endl;
goto re3;
}
}else if(option==2)
{
goto re;
}else
{
cout<<"您輸入的代碼有誤!"<<endl;
goto re2;
}
system("pause");
return 0;
}
複製代碼
作者:
田宇任
時間:
2019-3-16 10:08
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
re:
system("cls");
int sum=0;
int x,y,o,buy,corn;
string s[]={"珍珠奶茶","茉莉綠茶","泡沫紅茶","菊花茶","多多綠茶","梅子可樂","檸檬愛玉"};
int m[]={50,35,20,30,35,25,45};
int z[]={0,0,0,0,0,0,0};
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;
z[x-1]+=y;
sum+=m[x-1]*y;
}cout<<endl;
cout<<"[購物清單]"<<endl;
cout<<"---------------------"<<endl;
for(int i=0;i<7;i++)
{
if(z[i]!=0)
cout<<s[i]<<"\t"<<z[i]<<"元 * "<<z[i]<<"個"<<endl;
}
cout<<"---------------------";
cout<<endl<<"共"<<sum<<"元!"<<endl<<endl;
cout<<"1=正確無誤 2=重新選購 ";
cin>>o;
if(o==1)
{
cout<<"請付帳:";
cin>>buy;
corn=buy-sum;
if(corn<0)
{
cout<<"錢不夠喔,還差"<<sum-buy<<"元"<<endl;
}else if(corn==0)
{
cout<<"剛剛好,謝謝惠顧"<<endl;
}else
{
cout<<"找您"<<corn<<"元"<<endl;
if(corn>=500)
{
cout<<"五百元鈔票"<<corn/500<<"張"<<endl;
corn=corn%500;
}
if(corn>=100)
{
cout<<"一百元鈔票"<<corn/100<<"張"<<endl;
corn=corn%100;
}
if(corn>=10)
{
cout<<"五十元硬幣"<<corn/50<<"枚"<<endl;
corn=corn%50;
}
if(corn>=10)
{
cout<<"十元硬幣"<<corn/10<<"枚"<<endl;
corn=corn%10;
}
if(corn>=1)
{
cout<<"一元硬幣"<<corn/1<<"枚"<<endl;
}
}
}else
{
goto re;
}
system("pause");
return 0;
}
複製代碼
歡迎光臨 種子論壇 | 高雄市資訊培育協會學員討論區 (http://istak.org.tw/seed/)
Powered by Discuz! 7.2