標題:
智慧找零系統 (二)
[打印本頁]
作者:
王瑞喻
時間:
2020-7-16 16:34
標題:
智慧找零系統 (二)
設計一個更聰明的智慧找零系統, 包括客人付的錢
不足
,
剛好
, 或
任何
可能發生的狀況.
本帖隱藏的內容需要回復才可以瀏覽
作者:
李柏穎
時間:
2020-7-18 16:20
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
re:
system("cls");
int a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v;
cout<<"***智慧找零系統***"<<endl<<endl;
cout<<"請輸入商品價格: ";
cin>>a;
cout<<"客人付了多少錢: ";
cin>>b;
cout<<"須找客人多少錢: "<<b-a<<endl;
c=b-a;
d=c/1000;
e=d*1000;
f=c-e;
g=f/500;
h=g*500;
i=f-h;
j=i/100;
k=j*100;
l=i-k;
m=l/50;
n=m*50;
o=l-n;
p=o/10;
q=p*10;
s=o-q;
t=s/5;
u=t*5;
v=s-u;
if(b>a)
{
if(c/1000>0)
cout<<"一千元"<<c/1000<<"張"<<endl;
else
cout<<endl;
if(f/500>0)
cout<<"五百元"<<f/500<<"張"<<endl;
else
cout<<endl;
if(i/100>0)
cout<<"一百元"<<i/100<<"張"<<endl;
else
cout<<endl;
if(l/50>0)
cout<<"五十元"<<l/50<<"枚"<<endl;
else
cout<<endl;
if(o/10>0)
cout<<"十元"<<o/10<<"枚"<<endl;
else
cout<<endl;
if(s/5>0)
cout<<"五元"<<s/5<<"枚"<<endl;
else
cout<<endl;
if(v/1>0)
cout<<"一元"<<v/1<<"枚"<<endl;
else
cout<<endl;
}
else if(a==b)
cout<<"剛剛好! 銘謝惠顧!"<<endl;
else if(a>b)
cout<<"還差"<<a-b<<"元"<<endl;
else if(c>10000)
cout<<"錢太多? 全部送我吧!"<<endl;
else
cout<<endl;
system("pause");
goto re;
return 0;
}
複製代碼
作者:
鐘彥博
時間:
2020-7-18 16:56
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
int a,b,c;
cout<<"************智慧找零系統**********"<<endl;
cout<<"請輸入商品價格(元):";
cin>>a;
cout<<"客人付了多少錢(元):";
cin>>b;
if(a>b && b>=0)
{
c=a-b;
cout<<"客人還需付"<<c<<"元"<<endl;
}else if(b>a && a>=0)
{
c=b-a;
cout<<"總共需找客人"<<c<<"元"<<endl;
}else if(b=a && a>=0)
{
c=0;
cout<<"剛剛好,不用找!"<<endl;
}else
{
cout<<"輸入錯誤!"<<endl;
}
if(c>=500)
{
cout<<"五百元"<<c/500<<"張"<<endl;
}
if(c%500>=100)
{
cout<<"一百元"<<c%500/100<<"張"<<endl;
}
if(c%100>=50)
{
cout<<"五十元"<<c%100/50<<"個"<<endl;
}
if(c%50>=10)
{
cout<<"十元"<<c%50/10<<"個"<<endl;
}
if(c%10>=5)
{
cout<<"五元"<<c%10/5<<"個"<<endl;
}
if(c%5>=1)
{
cout<<"一元"<<c%5/1<<"個"<<endl;
}
system("pause");
return 0;
}
複製代碼
作者:
董定宇
時間:
2020-7-18 17:14
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
int price,pay,money;
cout<<"*** 智慧找零系統 ***"<<endl<<endl;
cout<<"請輸入商品價格"<<endl;
cin>>price;
cout<<"客人付了多少錢";
cin>>pay;
money=pay-price;
cout<<"要找客人"<<money<<"元"<<endl;
if(money==price)
{
cout<<"030" <<endl;
}
if(pay<price)
{
cout<<"幹你的差"<<price-pay<<"元"<<endl;
}
if(pay>price)
{
cout<<"'_>`"<<endl;
cout<<"要找客人"<<money<<"元"<<endl;
if(money>=500)
{
cout<<"五百元"<<money/500<<"張";
money=money%500;
}
if(money>=100)
{
cout<<"一百元"<<money/100<<"張";
money=money%100;
}
if(money>=50)
{
cout<<"五十元"<<money/50<<"枚";
money=money%50;
}
if(money>=10)
{
cout<<"十元"<<money/10<<"枚";
money=money%10;
}
if(money>=5)
{
cout<<"五元"<<money/5<<"枚";
money=money%5;
}
if(money>=1)
{
cout<<"一元"<<money<<"枚";
}
}
system("pause");
return 0;
}
複製代碼
作者:
潘堉恩
時間:
2020-7-18 17:22
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
re:
int price,pay,money;
cout<<"***智慧找零系統***"<<endl;
cout<<"請輸入商品價格";
cin>>price;
cout<<"客人付了多少錢";
cin>>pay;
money=pay-price;
if(money==0)
{
cout<<"剛剛好!銘謝惠顧!"<<endl;
}else if(money>1000)
{
cout<<"下次請用信用卡感謝!!!"<<endl;
}else if(price>pay)
{
cout<<"錢不夠!有錢再來!!!"<<price-pay<<"元"<<endl;
}else
{
cout<<endl<<"需找客人"<<money<<"元"<<endl<<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>=0)
{
cout<<"1元鈔票"<<money/1<<"枚"<<endl;
}
cout<<endl;
}
goto re;
system("pause");
return 0;
}
複製代碼
作者:
呂尚霖
時間:
2020-7-19 10:11
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
system("cls");
re:
int price,pay,money;
cout<<"***智慧找零系統*** "<<endl<<endl;
cout<<"請輸入商品價格:";
cin>>price;
cout<<"客人付了多少錢:";
cin>>pay;
money=pay-price;
if(price==pay)
{
cout<<"剛剛好!! "<<endl;
}
else if(pay<price)
{
cout<<"客人錢不夠!! "<<price-pay<<"元"<<endl;
}
else if(money>=1000)
{
cout<<"錢太多???? "<<endl;
}
else
{
cout<<endl<<"須找客人"<<money<<"元"<<endl<<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>0)
{
cout<<"一元鈔硬幣"<<money<<"枚"<<endl;
}
}
cout<<endl;
system("pause");
goto re;
return 0;
}
複製代碼
歡迎光臨 種子論壇 | 高雄市資訊培育協會學員討論區 (http://seed.istak.org.tw/)
Powered by Discuz! 7.2