標題:
智慧找零系統 (二)
[打印本頁]
作者:
陳育霖
時間:
2023-6-26 18:28
標題:
智慧找零系統 (二)
設計一個更聰明的智慧找零系統, 包括客人付的錢
不足
,
剛好
, 或
任何
可能發生的狀況.
本帖隱藏的內容需要回復才可以瀏覽
作者:
楊承樺
時間:
2023-6-27 20:48
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
int a,b,c;
cout<<"***智慧找零系統***"<<endl<<endl;
cout<<"請輸入商品價格: ";
cin>>a;
cout<<"客人付了多少錢: ";
cin>>b;
cout<<endl;
if(a>b)
{
cout<<"錢不夠喔! 還差"<<a-b<<"元";
}
else if(a==b)
{
cout<<"剛剛好! 銘謝惠顧!";
}
else if(b>100000)
{
cout<<"錢太多? 全部送我吧!";
}
else
{
c=b-a;
cout<<"須找客人"<<c<<"元"<<endl<<endl;
if(c/1000>0)
{
cout<<"一千元鈔票"<<c/1000<<"張"<<endl;
c=c%1000;
}
if(c/500>0)
{
cout<<"五百元鈔票"<<c/500<<"張"<<endl;
c=c%500;
}
if(c/100>0)
{
cout<<"一百元鈔票"<<c/100<<"張"<<endl;
c=c%100;
}
if(c/50>0)
{
cout<<"五十元硬幣"<<c/50<<"枚"<<endl;
c=c%50;
}
if(c/10>0)
{
cout<<"十元硬幣"<<c/10<<"枚"<<endl;
c=c%10;
}
if(c/5>0)
{
cout<<"五元硬幣"<<c/5<<"枚"<<endl;
c=c%5;
}
if(c/1>0)
{
cout<<"一元硬幣"<<c/1<<"枚"<<endl;
c=c%1;
}
}
cout<<endl;
system("pause");
return 0;
}
複製代碼
作者:
王閎民
時間:
2023-6-27 21:01
本帖最後由 王閎民 於 2023-6-29 13:39 編輯
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
int p=0,m=0;
cout<<"請輸入商品價格: ";
cin >>p;
cout<<"客人付了多少錢: ";
cin >>m;
cout<<endl;
if(m-p>=10000)
{
cout<<"錢太多了? 全部送我吧!"<<endl;
}
else if(m>p)
{
cout<<"需找客人"<<m-p<<"元"<<endl<<endl;
int a=m-p;
cout<<"500元鈔票"<<a/500<<"張"<<endl;
a=a-((a/500)*500);
cout<<"100元鈔票"<<a/100<<"張"<<endl;
a=a-((a/100)*100);
cout<<"50元鈔票"<<a/50<<"枚"<<endl;
a=a-((a/50)*50);
cout<<"10元鈔票"<<a/10<<"枚"<<endl;
a=a-((a/10)*10);
cout<<"1元鈔票"<<a<<"枚"<<endl;
}
else if(m<p)
{
cout<<endl<<"錢不夠喔! 還差"<<p-m<<"元!"<<endl;
}
else
{
cout<<endl<<"剛剛好! 銘謝惠顧!"<<endl;
}
system("pause");
return 0;
}
複製代碼
[/code]
作者:
李東諺
時間:
2023-6-27 23:34
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
int a,b,c;
cout<<"***智慧找零系統***"<<endl<<endl;
cout<<"請輸入商品價格: ";
cin>>a;
cout<<"客人付了多少錢: ";
cin>>b;
cout<<endl;
if(a>b)
{
cout<<"錢不夠喔! 還差"<<a-b<<"元";
}
else if(a==b)
{
cout<<"剛剛好! 銘謝惠顧!";
}
else if(b>100000)
{
cout<<"錢太多? 全部送我吧!";
}
else
{
c=b-a;
cout<<"須找客人"<<c<<"元"<<endl<<endl;
if(c/1000>0)
{
cout<<"一千元鈔票"<<c/1000<<"張"<<endl;
c=c%1000;
}
if(c/500>0)
{
cout<<"五百元鈔票"<<c/500<<"張"<<endl;
c=c%500;
}
if(c/100>0)
{
cout<<"一百元鈔票"<<c/100<<"張"<<endl;
c=c%100;
}
if(c/50>0)
{
cout<<"五十元硬幣"<<c/50<<"枚"<<endl;
c=c%50;
}
if(c/10>0)
{
cout<<"十元硬幣"<<c/10<<"枚"<<endl;
c=c%10;
}
if(c/5>0)
{
cout<<"五元硬幣"<<c/5<<"枚"<<endl;
c=c%5;
}
if(c/1>0)
{
cout<<"一元硬幣"<<c/1<<"枚"<<endl;
c=c%1;
}
}
cout<<endl;
system("pause");
return 0;
}
複製代碼
作者:
林家鉌
時間:
2023-6-28 09:04
#include <iostream>
#include <cstdlib>
using namespace std;
int main()
{
float a,b;
int c,d,e,f,fhd,ohd,ftd,td,fd;
cout<<"input prize: ";
cin>>a;
cout<<"input your money: ";
cin>>b;
d=b*100;
while(b<a)
{
cout<<"Not enough money, Error\nInput money: ";
cin>>b;
}
if(b>=a*1000)
{
cout<<"two much money bro!";
}
else if(b>a)
{
c=a*100;
d=b*100;
e=d-c;
cout<<"give change: "<<e/100<<" dollars\n\n";
fhd=e/50000;
e=e%50000;
ohd=e/10000;
e=e%10000;
ftd=e/5000;
e=e%5000;
td=e/1000;
e=e%1000;
fd=e/500;
e=e%500;
cout<<"give change:\n"<<fhd<<"five hundred dollars\n"<<ohd<<"one hundred dollars\n"<<ftd<<"fifty dollars\n"<<td<<"ten dollars\n"<<fd<<"five dollars\n"<<e/100<<"dollars\n";
}
else
{
cout<<"\njust enough!";
}
cout<<"Thank you!\n";
system("pause");
return 0;
}
複製代碼
作者:
李晨希
時間:
2023-6-28 22:29
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
int a=0,b=0,c=0,d=0,f=0,g=0,e=0,h=0;
cout<<"請輸入商品價格: ";
cin>>a;
cout<<"客人付了多少錢: ";
cin>>b;
cout<<endl;
cout<<"需找客人"<<b-a<<"元"<<endl<<endl;
c=b-a;
d=c%500;
e=d%100;
f=e%50;
g=f%10;
if(b<a) //不足錢
cout<<"錢不夠喔!還差"<<a-b<<"元"<<endl;
else if(b==a)
cout<<"剛剛好!銘謝惠顧!" <<endl;
else
cout<<"錢太多?全部送我吧!"<<endl;
cout<<endl<<"500元鈔票"<<c/500<<"張"<<endl<<"100元鈔票"<<d/100<<"張"<<endl<<"50元硬幣"<<e/50<<"枚"<<endl<<"10元硬幣"<<f/10<<"枚"<<endl;
system("pause");
return 0;
}
複製代碼
作者:
陳姿瑜
時間:
2023-6-29 08:18
本帖最後由 陳姿瑜 於 2023-6-29 20:49 編輯
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
re:
int a,pay,c;
cout<<"請輸入商品價格: ";
cin>>a;
cout<<"客人付了多少錢? ";
cin>>pay;
cout<<endl<<endl;
if(a==pay)
{
cout<<"剛剛好! 銘謝惠顧!"<<endl;
}
else if(pay>1000000)
{
cout<<"錢太多! 全部送給我吧!"<<endl;
}
else if(a>pay)
{
cout<<"錢不夠喔! 還差"<<a-pay<<"元"<<endl;
}
else
{
cout<<"須找客人"<<(pay-a)<<"元"<<endl<<endl;
c=pay-a;
if(c/500>0)
{
cout<<"五百塊"<<c/500<<"張"<<endl;
c=c%500;
}
if(c/100>0)
{
cout<<"一百塊"<<c/100<<"張"<<endl;
c=c%100;
}
if(c/50>0)
{
cout<<"五十元"<<c/50<<"枚"<<endl;
c=c%50;
}
if(c/10>0)
{
cout<<"十元"<<c/10<<"枚"<<endl;
c=c%10;
}
if(c/5>0)
{
cout<<"五元"<<c/5<<"枚"<<endl;
c=c%5;
}
if(c/1>0)
{
cout<<"一元"<<c/1<<"枚"<<endl;
}
goto re;
system("pause");
return 0;
}
複製代碼
作者:
孟涵
時間:
2023-6-29 15:11
本帖最後由 孟涵 於 2023-6-29 19:14 編輯
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
int a,b,c,d,e,f,g;
cout<<"***智慧找零系統***"<<endl<<endl;
cout<<"請輸入商品價格: ";
cin>>a;
cout<<"客人付了多少錢: ";
cin>>b;
cout<<endl;
if(a>b)
{
cout<<"錢不夠喔!還差"<<a-b<<"元";
}
else if(a==b)
{
cout<<"剛剛好!謝謝惠顧!";
}
else if (b>9999)
{
cout<<"錢太多? 全部送我吧!"<<endl;
}
else
{
c=b-a;
cout<<"須找客人"<<c<<"元"<<endl<<endl;
g=b-a;
if(g/500>0)
cout<<"500元鈔票"<<g/500<<"張"<<endl;
c=g%500;
if(c/100>0)
cout<<"100元鈔票"<<c/100<<"張"<<endl;
d=c%100;
if(d/50>0)
cout<<"50元硬幣"<<d/50<<"枚"<<endl;
e=d%50;
if(e/10>0)
cout<<"10元硬幣"<<e/10<<"枚"<<endl;
f=e%10;
if(f/1>0)
cout<<"1元硬幣"<<f/1<<"枚"<<endl;
}
system("pause");
return 0;
}
複製代碼
作者:
蕭宏宇
時間:
2023-6-29 15:40
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
int a=0,b=0;
cout<<"***智慧找零系統***"<<endl<<endl;
cout<<"請輸入商品價格: ";
cin>>a;
cout<<"客人付了多少錢: "<<endl;
cin>>b;
if(a>b)
cout<<"錢不夠喔! 還差"<<a-b<<"元"<<endl;
else if(a==b)
{
cout<<"剛剛好! 銘謝惠顧!";
}
else if(b-a>=10000)
{
cout<<"錢太多了? 全部送我吧!"<<endl;
}
else
{
cout<<"須找客人"<<b-a<<"元";
cout<<"五百元鈔票"<<(b-a)/500<<"元;";
cout<<"一百元鈔票"<<(b-a)%500/100<<"元";
cout<<"五十元硬幣"<<(b-a)%500%100/50<<"元";
cout<<"十元硬幣"<<(b-a)%500%100%50/10<<"元";
cout<<"五元硬幣"<<(b-a)%500%100%50%10/5<<"元";
cout<<"一元硬幣"<<(b-a)%500%100%50%10%5/1<<"元";
}
system("pause");
return 0;
}
複製代碼
作者:
徐楷恩
時間:
2023-6-29 16:15
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
cout<<"***智慧找零系統***"<<endl<<endl;
int a,s,d,f,g,h,j;
cout<<"請輸入商品價格: ";
cin>>a;
cout<<"客人付了多少錢: ";
cin>>s;
cout<<endl;
if(a>s)
{
cout<<"錢不夠喔!還差"<<a-s<<"元";
}
else if(a==s)
{
cout<<"剛剛好!謝謝惠顧!";
}
else if (s>9999)
{
cout<<"錢太多? 全部送我吧!"<<endl;
}
else
{
d=s-a;
cout<<"須找客人"<<d<<"元"<<endl<<endl;
j=s-a;
cout<<"500元鈔票"<<j/500<<"張"<<endl;
d=j%500;
cout<<"100元鈔票"<<d/100<<"張"<<endl;
f=d%100;
cout<<"50元硬幣"<<f/50<<"枚"<<endl;
g=f%50;
cout<<"10元硬幣"<<g/10<<"枚"<<endl;
h=g%10;
cout<<"1元硬幣"<<h/1<<"枚"<<endl;
}
system("pause");
return 0;
}
複製代碼
作者:
陳曜誌
時間:
2024-7-12 21:02
#include<iostream>
using namespace std;
int main()
{
cout << "*** 智慧找零系統 ***" << endl;
cout << "請輸入商品價格: ";
int price, pay;
cin >> price;
cout << "客人付了多少錢: ";
cin >> pay;
int money = pay-price;
if(money>=1000)
cout<<endl<<"錢太多?全部送我吧!"<<endl;
else if(money>0 && money <1000)
{
cout << "須找客人" << money << "元\n";
if(money>=500) {
cout << "五百元鈔票 "<< money / 500 << "張" << endl;
money%=500;
}
if(money>=100) {
cout << "一百元鈔票 " << (money % 500)/100 << "張" << endl;
money%=100;
}
if(money>=50) {
cout << "五十元硬幣 " << (money % 100)/50 << "枚" << endl;
money%=50;
}
if(money>=10) {
cout << "十元硬幣 " << (money % 50)/10 << "枚" << endl;
money%10;
}
if(money>0)
cout << "一元硬幣 " << (money % 10) << "枚" << endl;
}
else if(money == 0)
cout<<endl<<"剛剛好!銘謝惠顧!"<<endl;
else
cout << "錢不夠喔!還差" << (-money) << "元" << endl;
}
複製代碼
作者:
陳曜誌
時間:
2024-7-12 21:09
#include <iostream>
using namespace std;
int main()
{
re:
cout << "*** 智慧找零系統 ***" << endl;
cout << "請輸入商品價格: ";
int price, pay;
cin >> price;
cout << "客人付了多少錢: ";
cin >> pay;
int money = pay - price;
if (money >= 1000)
cout << endl << "錢太多?全部送我吧!" << endl;
else if (money > 0 && money < 1000)
{
cout << "須找客人" << money << "元\n";
int change[5] = {500, 100, 50, 10, 1};
string names[5] = {"五百元鈔票", "一百元鈔票", "五十元硬幣", "十元硬幣", "一元硬幣"};
for (int i = 0; i < 5; ++i)
{
int count = money / change[i];
if (count > 0)
{
cout << names[i] << " " << count << (i < 2 ? "張" : "枚") << endl;
money %= change[i];
}
}
}
else if (money == 0)
cout << endl << "剛剛好!銘謝惠顧!" << endl;
else
cout << "錢不夠喔!還差" << (-money) << "元" << endl;
goto re;
return 0;
}
複製代碼
作者:
李昱辰
時間:
2024-7-22 19:48
#include<iostream>
using namespace std;
int main()
{
re:
int price=0,pay=0;
int change,x;
cout<<"*** 智慧找零系統 ***"<<endl;
cout<<endl;
cout<<"請輸入商品價格:";
cin>>price;
cout<<"客人付了多少錢:";
cin>>pay;
cout<<endl;
change=pay-price;
if(change==0)
{
cout<<"剛剛好!銘謝惠顧!"<<endl;
}
else if(change<0)
{
x=price-pay;
cout<<"錢不夠喔!還差"<<x<<"元!"<<endl;
}
else if(change>1000)
{
cout<<"錢太多?全部送我吧!"<<endl;
}
else if(change>0)
{
cout<<"需找客人"<<change<<"元"<<endl;
cout<<endl;
if(change/500>0)
{
cout<<"五百元鈔票"<<change/500<<"張"<<endl;
change=change%500;
}
if(change/100>0)
{
cout<<"一百元鈔票"<<change/100<<"張"<<endl;
change=change%100;
}
if(change/50>0)
{
cout<<"五十元硬幣"<<change/50<<"枚"<<endl;
change=change%50;
}
if(change/10>0)
{
cout<<"十元硬幣"<<change/10<<"枚"<<endl;
change=change%10;
}
if(change/1>0)
{
cout<<"一元硬幣"<<change/1<<"枚"<<endl;
}
}
else
{
cout<<"輸入錯誤"<<endl;
}
goto re;
}
複製代碼
歡迎光臨 種子論壇 | 高雄市資訊培育協會學員討論區 (http://seed.istak.org.tw/)
Powered by Discuz! 7.2