標題:
[作業] 智慧找零系統進階
[打印本頁]
作者:
tonyh
時間:
2013-11-30 17:32
標題:
[作業] 智慧找零系統進階
本帖最後由 tonyh 於 2013-11-30 17:58 編輯
設計一個更聰明的智慧找零系統, 包括客人付的錢不足, 剛好, 或
任何
可能發生的其他情況.
作者:
施伯叡
時間:
2013-11-30 17:45
#include <iostream>
#include <cstdlib>
using namespace std;
int main()
{
int price,pay,money;
cout<<"***智慧找零系統***"<<endl<<endl;
cout<<"請輸入商品價格: ";
cin>>price;
cout<<"請輸入客人付的錢: ";
cin>>pay;
money=pay-price;
if(price<pay)
{
cout<<"你應該找給客人"<<money<<"元"<<endl;
}
if(money==0)
{
cout<<"你付的錢剛剛好,謝謝惠顧!"<<endl;
}
if(pay<price)
{
cout<<"你付的錢不對優,還差"<<price-pay<<"元"<<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;
}
system("pause");
return 0;
}
複製代碼
作者:
張峻瑋
時間:
2013-11-30 18:04
本帖最後由 張峻瑋 於 2014-2-22 17:06 編輯
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
start:
string name[7]={"遙控飛機",
"水槍 ",
"玩偶 ",
"足球 ",
"拼圖 ",
"籃球 ",
"玩具車"};
int price[7]={50000,6500000,70000,655000,999999,300000,750000,};
int qty[7]={0,0,0,0,0,0,0};
int p,q,sum=0,option,pay,money;
cout<<"***貴死人玩具店***"<<endl<<endl;
cout<<"[商品價目表]"<<endl;
for(int i=0;i<=6;i++)
{
cout<<"("<<i+1<<")"<<name[i]<<"\t"<<price[i]<<"元"<<endl;
}
cout<<"(8)結帳"<<endl;
re:
cout<<"請輸入商品代碼:"<<endl;
cin>>p;
if(p>=1 && p<=7)
{
cout<<"請輸入數量:"<<endl;
cin>>q;
if(q>0)
{
sum+=price[p-1]*q;
qty[p-1]+=q;
goto re;
}
else
{
cout<<"輸入錯誤!"<<endl;
goto re;
}
}
else if(p==8)
{
goto checkout;
}
else
{
cout<<"輸入錯誤!"<<endl;
goto re;
}
checkout:
cout<<"[購物清單]"<<endl;
cout<<"==========================="<<endl;
for(int i=0;i<=6;i++)
{
if(qty[i]!=0)
cout<<"("<<i+1<<")"<<name[i]<<"\t"<<price[i]<<"元*"<<qty[i]<<"個"<<endl;
}
cout<<"==========================="<<endl;
cout<<endl<<"總共"<<sum<<"元!"<<endl<<endl;
cout<<"1-正確無誤 2-重新選購"<<endl;
cin>>option;
if(option==1)
{
goto pay;
}
else if(option==2)
{
system("cls");
goto start;
}
else
{
cout<<"輸入錯誤!"<<endl;
goto start;
}
pay:
cout<<"請付帳:";
cin>>pay;
money=pay-sum;
if(money<0)
{
cout<<"您付的錢還不夠,還差"<<-money<<"元!"<<endl;
goto pay;
}
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<<"枚"<<endl;
money=money%1;
}
}
system("pause");
return 0;
}
複製代碼
作者:
張彥承
時間:
2013-11-30 18:04
#include<iostream>
#include<cstdlib>
using namespace std;
int main ()
{
int total,cm,givingmoney;
cout<<"***intelligent money-giving machine***"<<endl;
cout<<"the purchase cost:"<<endl;
cin>>total;
cout<<"customers shell out:"<<endl;
cin>>cm;
givingmoney=cm-total;
cout<<"you need to give: "<<givingmoney<<endl;
if(givingmoney<0)
{
cout<<"your money is not enough!you need to pay"<<-givingmoney<<"dollars"<<endl;
}
if(givingmoney==0)
{
cout<<"you pay the same!thanks!"<<endl;
}else
{
if(givingmoney>=500)
{
cout<<"500 dollar bills: "<<givingmoney/500<<" piece"<<endl;
givingmoney=givingmoney%500;
} if(givingmoney>=100)
{
cout<<"100 dollar bills: "<<givingmoney/100<<" piece"<<endl;
givingmoney=givingmoney%100;
} if(givingmoney>=50)
{
cout<<"50 dollar coin: "<<givingmoney/50<<" cookie"<<endl;
givingmoney=givingmoney%50;
} if(givingmoney>=10)
{
cout<<"10 dollar coin: "<<givingmoney/10<<" cookie"<<endl;
givingmoney=givingmoney%10;
}if(givingmoney>=5)
{
cout<<"5 dollar coin: "<<givingmoney/5<<" cookie"<<endl;
givingmoney=givingmoney%5;
}if(givingmoney>=1)
{
cout<<"1 dollar coin: "<<givingmoney/1<<" cookie"<<endl;
givingmoney=givingmoney%1;
}if(givingmoney=total)
{
cout<<"you pay the same,thanks!"<<endl;
}if(givingmoney<total)
{
givingmoney=total-givingmoney;
cout<<"that is not enough,YOU NEED TO PAY:"<<givingmoney<<"dollar smore"<<endl;
}
}
system("pause");
return 0;
}
複製代碼
作者:
張郁庭
時間:
2013-11-30 18:04
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
int price,pay,money;
cout<<"****智慧找零系統****"<<endl;
cout<<"請輸入商品的價格:"<<endl;
cin>>price;
cout<<"請輸入客人付了多少錢:"<<endl;
cin>>pay;
money=pay-price;
if(price<pay)
{
cout<<"你應該找給客人"<<money<<"元"<<endl;
}
if(money==0)
{
cout<<"你付的錢剛剛好! 謝謝惠顧!"<<endl;
}
if(pay<price)
{
cout<<"你付的錢不對喔! 還差"<<price-pay<<"元"<<endl;
}
if(money>=500)
{
cout<<"500元鈔票"<<money/500<<"張"<<endl;
money=money%500;
}
if(money>=100)
{
cout<<"100元鈔票"<<money/100<<"張"<<endl;
money=money%100;
}
if(money>=50)
{
cout<<"50元硬幣"<<money/50<<"張"<<endl;
money=money%50;
}
if(money>=10)
{
cout<<"10元硬幣"<<money/10<<"枚"<<endl;
money=money%10;
}
if(money>=5)
{
cout<<"5元硬幣"<<money/5<<"枚"<<endl;
money=money%5;
}
if(money>=1)
{
cout<<"1元硬幣"<<money/1<<"枚"<<endl;
money=money%1;
}
system ("pause");
return 0;
}
複製代碼
作者:
周雍程
時間:
2013-11-30 18:05
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
int price, pay, money;
cout<<"*** 智慧找零系統 ***"<<endl<<endl;
cout<<"請輸入商品價格:";
cin >> price;
cout<<"請輸入要付的錢:";
cin >> pay;
money = pay-price;
if(money==0)
{
cout<<"剛剛好,請慢走"<<endl;
}
if(pay<price)
{
cout<<"您付的錢不夠喔,還要付"<<-money<<"元"<<endl;
}
if(price<pay)
cout<<"須找的錢是:"<<money<<endl;
if(money>=500)
{
cout<<"500元鈔票"<<money/500<<"張"<<endl;
money=money%500;
}
if(money>=100)
{
cout<<"100元鈔票"<<money/100<<"張"<<endl;
money=money%100;
}
if(money>=50)
{
cout<<"50元硬幣"<<money/50<<"枚"<<endl;
money=money%50;
}
if(money>=10)
{
cout<<"10元硬幣"<<money/10<<"枚"<<endl;
money=money%10;
}
if(money>=5)
{
cout<<"5元硬幣"<<money/5<<"枚"<<endl;
money=money%5;
}
if(money>=1)
{
cout<<"1元硬幣"<<money/1<<"枚"<<endl;
money=money%1;
}
system("pause");
return 0;
}
複製代碼
作者:
張郁偵
時間:
2013-11-30 18:08
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
int total,pay,money;
cout<<"****智慧找零系統****"<<endl;
cout<<"請輸入商品價格: ";
cin>>total;
cout<<"請輸入你所要付的金額: ";
cin>>pay;
money=pay-total;
if(money<0)
{
cout<<"您付的錢不夠喔,還差"<<-money<<"元"<<endl;
}else if(money==0)
{
cout<<"剛剛好!謝謝惠顧!"<<endl;
}else
{
cout<<"總共要找"<<money<<"元!"<<endl;
if(money>=500)
{
cout<<"500元鈔票"<<money/500<<"張"<<endl;
money=money%500;
}
if(money>=100)
{
cout<<"100元鈔票"<<money/100<<"張"<<endl;
money=money%100;
} if(money>=50)
{
cout<<"50元硬幣"<<money/50<<"枚"<<endl;
money=money%50;
} if(money>=10)
{
cout<<"10元硬幣"<<money/10<<"枚"<<endl;
money=money%10;
} if(money>=5)
{
cout<<"5元硬幣"<<money/5<<"枚"<<endl;
money=money%5;
} if(money>=1)
{
cout<<"1元硬幣"<<money/1<<"枚"<<endl;
money=money%1;
}
}
system ("pause");
return 0;
}
複製代碼
作者:
劉得旗
時間:
2013-12-7 15:41
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
int price,pay,money;
cout<<"超級智慧找零系統"<<endl<<endl;
cout<<"輸入商品價格:";
cin>>price;
cout<<"輸入客人pay了多少錢:";
cin>>pay;
money=pay-price;
if(money<0)
{
cout<<"sorry!!你付的錢還差"<<price-pay<<"元!"<<endl;
}
else if(money==0)
{
cout<<"你付的錢剛好,謝謝惠顧"<<endl;
}
else
{
cout<<"總共要找客人"<<money<<"元!"<<endl;
if(money>=500)
{
cout<<"500元鈔票"<<money/500<<"張"<<endl;
money=money%500;
}
if(money>=100)
{
cout<<"100元鈔票"<<money/100<<"張"<<endl;
money=money%100;
}
if(money>=50)
{
cout<<"50元硬幣"<<money/50<<"枚"<<endl;
money=money%50;
}
if(money>=10)
{
cout<<"10元硬幣"<<money/10<<"枚"<<endl;
money=money%10;
}
if(money>=5)
{
cout<<"5元硬幣"<<money/5<<"枚"<<endl;
money=money%5;
}
if(money>=1)
{
cout<<"1元硬幣"<<money/1<<"枚"<<endl;
money=money%1;
}
}
system("pause");
return 0;
}
複製代碼
歡迎光臨 種子論壇 | 高雄市資訊培育協會學員討論區 (http://istak.org.tw/seed/)
Powered by Discuz! 7.2