標題:
[作業]智慧找零系統 (二)
[打印本頁]
作者:
陳品肇
時間:
2018-12-14 23:58
標題:
[作業]智慧找零系統 (二)
本帖最後由 陳品肇 於 2018-12-15 14:14 編輯
設計一個更聰明的智慧找零系統, 包括客人付的錢不足, 剛好, 或任何可能發生的狀況(超出商品價格的10倍).
[attach]5571[/attach]
作者:
趙一鳴
時間:
2018-12-15 14:42
本帖最後由 趙一鳴 於 2018-12-15 15:28 編輯
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
int price,pay,tmp;
re:
cout<<"***智慧找零系統***\n\n請輸入商品價格: ";
cin>>price;
cout<<"客人付了多少錢: ";
cin>>pay;
tmp=pay-price;
if(pay>price)
{
cout<<"\n需找客人"<<tmp<<"元\n\n";
cout<<"五百元鈔票"<<tmp/500<<"張\n";
cout<<"一百元鈔票"<<(tmp%500)/100<<"張\n";
cout<<"五十元硬幣"<<((tmp%500)%100)/50<<"枚\n";
cout<<"十元硬幣"<<(((tmp%500)%100)%50)/10<<"枚\n";
cout<<"一元硬幣"<<(((tmp%500)%100)%50)%10<<"枚\n\n";
}else if(price==pay)
{
cout<<"剛剛好!銘謝惠顧!!\n";
}else if(pay<price)
{
cout<<"錢不夠喔!還差"<<price-pay<<"元!\n";
}else if(pay>=10*price)
{
cout<<"錢太多了!老兄!\n";
}else
{
cout<<"輸入錯誤\n";
}goto re;
system("pause");
return 0;
}
複製代碼
作者:
章幼莛
時間:
2018-12-15 15:11
本帖最後由 章幼莛 於 2018-12-15 15:30 編輯
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
start:
cout<<"***智慧找零系統***\n"<<endl;
int a,b,c,d;
cout<<"請輸入商品價格:";
cin>>a;
cout<<"客人付了:";
cin>>b;
c=b-a;
cout<<"須找的錢:"<<c<<endl;
if(c>0 && c<=10000)
{
d=c/500;
cout<<"500元"<<d<<"張\n"<<endl;
d=c%500/100;
cout<<"100元"<<d<<"張\n"<<endl;
d=c%100/50;
cout<<"50元"<<d<<"個\n"<<endl;
d=c%50/10;
cout<<"10元"<<d<<"個\n"<<endl;
d=c%10/5;
cout<<"5元"<<d<<"個\n"<<endl;
d=c%5;
cout<<"1元"<<d<<"個\n"<<endl;
}else if(c==0)
{
cout<<"剛剛好!銘謝惠顧~\n"<<endl;
}else if(c<0)
{
cout<<"錢不夠哦~還差"<<a-b<<"元\n"<<endl;
}else if(c>=a*10)
{
cout<<"你錢好多喔~不要炫富啦!\n"<<endl;
}
goto start;
system("pause");
return 0;
}
複製代碼
回復
1#
陳品肇
作者:
王瑞喻
時間:
2018-12-15 15:30
本帖最後由 王瑞喻 於 2018-12-16 12:38 編輯
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
re:
int price,money,tmp;
cout<<"請輸入商品價格:";
cin>>price;
cout<<"客人付錢:";
cin>>money;
tmp=money-price;
if(price*10<money)
{
cout<<"錢太多?全部送我吧!!";
}else if(price>money)
{
cout<<"錢不夠喔!還差"<<price-money<<"元!"<<endl;
}else if(price==money)
{
cout<<"剛剛好!銘謝惠顧!" ;
}else
{
cout<<"需找客人"<<tmp<<"元"<<endl;
if(tmp>=500)
{
cout<<"五百元鈔票"<<tmp/500<<"張"<<endl;
tmp=tmp%500;
}
if(tmp>=100)
{
cout<<"一百元鈔票"<<tmp/100<<"張"<<endl;
tmp=tmp%100;
}
if(tmp>=50)
{
cout<<"五十元硬幣"<<tmp/50<<"枚"<<endl;
tmp=tmp%50;
}
if(tmp>=10)
{
cout<<"十元硬幣"<<tmp/10<<"枚"<<endl;
tmp=tmp%10;
}
if(tmp>0)
{
cout<<"一元硬幣"<<tmp<<"枚"<<endl;
}
}
goto re;
system("pause");
return 0;
}
複製代碼
作者:
吳孟修
時間:
2018-12-15 15:31
本帖最後由 吳孟修 於 2018-12-22 18:40 編輯
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
re:
int x,y,z;
cout<<"***智慧找零系統***"<<endl;
cout<<"請輸入商品金額:";
cin>>x;
cout<<"請輸入付錢金額:";
cin>>y;
z=y-x;
if(z==0)
{
cout<<"剛剛好,銘謝惠顧!"<<endl;
}
else if(z<0)
{
cout<<"金錢不足,還差"<<-z<<"元"<<endl;
}
else if(y>=10*x)
{
cout<<"金額過大"<<endl;
}
else
{
cout<<"找錢金額:"<<z<<endl;
if(z>=500)
{
cout<<"五百元鈔票"<<z/500<<"張"<<endl;
z=z%500;
}
if(z>=100)
{
cout<<"一百元鈔票"<<z/100<<"張"<<endl;
z=z%100;
}
if(z>=50)
{
cout<<"五十元硬幣"<<z/50<<"枚"<<endl;
z=z%50;
}
if(z>=10)
{
cout<<"十元硬幣"<<z/10<<"枚"<<endl;
z=z%10;
}
if(z>=5)
{
cout<<"五元硬幣"<<z/5<<"枚"<<endl;
z=z%5;
}
if(z>=1)
{
cout<<"一元硬幣"<<z<<"枚"<<endl;
}
}
goto re;
system("pause");
return 0;
}
複製代碼
作者:
曲書辰
時間:
2018-12-19 18:56
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
int a,b,c,d;
cout<<"***智慧找零系統***"<<endl;
cout<<"請輸入商品價格:";
cin>>a;
cout<<"客人付了多少錢:";
cin>>b;
c=b-a;
d=b-a;
if(a==b)
{
cout<<"剛剛好!銘謝惠顧!!"<<endl;
}
else if(b<a && c<10)
{
cout<<"錢不夠喔! ,還差"<<b-a<<"元"<<endl;
}
else if(b>a)
{
cout<<"要找:"<<d<<"元"<<endl;
if(d>=500)
{
cout<<"500:"<<d/500<<"張"<<endl;
d=d%500;
}
if(d>=100)
{
cout<<"100:"<<d/100<<"張"<<endl;
d=d%100;
}if(d>=50)
{
cout<<"50:"<<d/50<<"枚"<<endl;
d=d%50;
}if(d>=10)
{
cout<<"10:"<<d/10<<"枚"<<endl;
d=d%10;
}if(d>=5)
{
cout<<"5:"<<d/5<<"枚"<<endl;
d=d%5;
}
if(d>=1)
{
cout<<"1:"<<d<<"枚"<<endl;
}
}
else
{
cout<<"錯誤"<<b-a<<endl;
}
system("pause");
return 0;
}
複製代碼
作者:
洪寬瀧
時間:
2018-12-21 22:16
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
int price,jeb,tmp;
jeb:
cout<<"***智慧找零系統***請輸入價錢: "
cin>>price;
cout<<"客人付了多少錢:";
cin>>jeb;
tmp=jeb-price;
if(jeb>price)
{
cout<<"須找客人"<<tmp<<"元";
cout<<"五百元鈔票"<<tmp/500<<"元";
cout<<"一百元鈔票"<<(tmp%500)100<<"元";
cout<<"五十元硬幣"<<((tmp%500)%100)/50<<"元";
cout<<"十元硬幣"<<(((tmp%500)%100)%50)/10<<"元";
cout<<"一元硬幣"<<((tmp%500)%100)%10<<"元";
}else if(price==jeb)
{
cout<<"嘟嘟好!銘謝惠顧";
}else if(jeb<price)
{
cout<<"錢不夠歐!";
}else if(jeb>price*10)
{
cout<<"你錢太多? 給我吧!";
}else
{
cout<<"輸入錯誤!";
}goto jeb;
system("pause");
return 0;
}
複製代碼
作者:
吳孟書
時間:
2018-12-22 18:45
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
cout<<"***智慧找零系統***"<<endl;
cout<<endl;
int price,money,tmp;
cout<<"請輸入商品價格:";
cin>>price;
cout<<"客人付了多少錢:";
cin>>money;
tmp=money-price;
cout<<endl;
if(price*10<=money)
{
cout<<"錢太多?全部送我吧!!"<<endl;
}else if(price>money)
{
cout<<"錢不夠喔!還差"<<price-money<<"元!"<<endl;
}else if(price==money)
{
cout<<"剛剛好!銘謝惠顧!"<<endl;
}else
{
cout<<"需找客人"<<tmp<<"元"<<endl;
cout<<endl;
if(tmp>=500)
{
cout<<"五百元鈔票"<<tmp/500<<"張"<<endl;
tmp=tmp%500;
}
if(tmp>=100)
{
cout<<"一百元鈔票"<<tmp/100<<"張"<<endl;
tmp=tmp%100;
}
if(tmp>=50)
{
cout<<"五十元硬幣"<<tmp/50<<"枚"<<endl;
tmp=tmp%50;
}
if(tmp>=10)
{
cout<<"十元硬幣"<<tmp/10<<"枚"<<endl;
tmp=tmp%10;
}
if(tmp>0)
{
cout<<"一元硬幣"<<tmp<<"枚"<<endl;
}
}
system("pause");
return 0;
}
複製代碼
歡迎光臨 種子論壇 | 高雄市資訊培育協會學員討論區 (http://seed.istak.org.tw/)
Powered by Discuz! 7.2