標題:
[作業] 智慧找零系統 (二)
[打印本頁]
作者:
tonyh
時間:
2014-11-22 11:39
標題:
[作業] 智慧找零系統 (二)
本帖最後由 tonyh 於 2014-11-29 11:05 編輯
設計一個更聰明的智慧找零系統, 包括客人付的錢
不足
,
剛好
, 或
任何
可能發生的狀況.
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
int price, pay, money;
cout<<"*** 智慧找零系統 ***"<<endl<<endl;
cout<<"請輸入商品價格: ";
cin>>price;
if(price<=0)
{
cout<<endl<<"你是奧客啊?!"<<endl<<endl;
goto end;
}
cout<<"客人付了多少錢: ";
cin>>pay;
if(pay<=0)
{
cout<<endl<<"你是奧客啊?!"<<endl<<endl;
goto end;
}
money=pay-price;
if(money<0)
{
cout<<endl<<"錢不夠喔! 還差"<<-money<<"元!"<<endl<<endl;
}else if(money==0)
{
cout<<endl<<"剛剛好! 銘謝惠顧!"<<endl<<endl;
}else if(money>=10000)
{
cout<<endl<<"錢太多? 全部送我吧!"<<endl<<endl;
}
else
{
cout<<endl<<"需找客人"<<money<<"元"<<endl<<endl;
if(money>=500)
{
cout<<"五百元鈔票"<<money/500<<"張"<<endl;
money%=500; //money=money%500;
}
if(money>=100)
{
cout<<"一百元鈔票"<<money/100<<"張"<<endl;
money%=100;
}
if(money>=50)
{
cout<<"五十元硬幣"<<money/50<<"枚"<<endl;
money%=50;
}
if(money>=10)
{
cout<<"十元硬幣"<<money/10<<"枚"<<endl;
money%=10;
}
if(money>=5)
{
cout<<"五元硬幣"<<money/5<<"枚"<<endl;
money%=5;
}
if(money>=1)
{
cout<<"一元硬幣"<<money<<"枚"<<endl;
}
cout<<endl;
}
end:
system("pause");
return 0;
}
複製代碼
作者:
李知易
時間:
2014-11-22 12:07
本帖最後由 李知易 於 2014-11-29 11:07 編輯
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
int price, pay, money;
cout<<"*** 智慧找零系統 ***"<<endl<<endl;
cout<<"請輸入商品價格: ";
cin>>price;
if(price<=0)
{
cout<<endl<<"你是誰啊?!"<<endl<<endl;
goto end;
}
cout<<"客人付了多少錢: ";
cin>>pay;
if(pay<=0)
{
cout<<endl<<"你是誰啊?!"<<endl<<endl;
goto end;
}
money=pay-price;
if(money<0)
{
cout<<endl<<"錢不夠喔! 還差"<<-money<<"元!"<<endl<<endl;
}else if(money==0)
{
cout<<endl<<"剛剛好! 銘謝惠顧!"<<endl<<endl;
}else if(money>=10000)
{
cout<<endl<<"錢太多? 全部送我吧!"<<endl<<endl;
}
else
{
cout<<endl<<"需找客人"<<money<<"元"<<endl<<endl;
if(money>=500)
{
cout<<"五百元鈔票"<<money/500<<"張"<<endl;
money%=500; //money=money%500;
}
if(money>=100)
{
cout<<"一百元鈔票"<<money/100<<"張"<<endl;
money%=100;
}
if(money>=50)
{
cout<<"五十元硬幣"<<money/50<<"枚"<<endl;
money%=50;
}
if(money>=10)
{
cout<<"十元硬幣"<<money/10<<"枚"<<endl;
money%=10;
}
if(money>=5)
{
cout<<"五元硬幣"<<money/5<<"枚"<<endl;
money%=5;
}
if(money>=1)
{
cout<<"一元硬幣"<<money<<"枚"<<endl;
}
cout<<endl;
}
end:
system("pause");
return 0;
}
複製代碼
作者:
謝瀞儀
時間:
2014-11-28 19:55
本帖最後由 謝瀞儀 於 2014-11-29 11:17 編輯
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
cout<<"歡迎光臨沒良心腦殘機器找零系統,今天也要來多收你ㄉ淺前優!"<<"\n"<<"\n";
long a,b,c;
cout<<"請蘇錄你花ㄌ多小淺前:";
cin>>a;
if(a<=0)
{
cout<<"奧客!xㄋ楊的下次別再給老子來ㄌ!"<<"\n";
goto fin;
}
cout<<"嗑輪給ㄉ淺前:";
cin>>b;
if(b<=0)
{
cout<<"沒淺前素不素,變搜橋拉!xㄋ楊的下次別再給老子來ㄌ!"<<"\n";
goto fin;
}
c=b-a;
cout<<"\n"<<"鬚腳嗑輪多小淺前:"<<c<<"個"<<"\n";
if(c>10000)
cout<<"你淺前太多齁,送偶一點也買擦拉!"<<"\n";
if(c==0)
cout<<"去死前不給偶,下次別再來ㄌ,繳0快拉!"<<"\n";
if(c>=2000)
{
cout<<"2000原敲竹槓的票:"<<c/2000<<"個"<<"\n";
c%=2000;
}
if(c>=1000)
{
cout<<"1000原敲竹槓的票:"<<c/1000<<"個"<<"\n";
c%=1000;
}
if(c>=500)
{
cout<<"500原敲竹槓的票:"<<c/500<<"個"<<"\n";
c%=500;
}
if(c>=100)
{
cout<<"100原敲竹槓的票:"<<c/100<<"個"<<"\n";
c%=100;
}
if(c>=50)
{
cout<<"50原ㄉ淺前:"<<c/50<<"個"<<"\n";
c%=50;
}
if(c>=10)
{
cout<<"10原ㄉ淺前:"<<c/10<<"個"<<"\n";
c%=10;
}
if(c>=5)
{
cout<<"5原ㄉ淺前:"<<c/5<<"個"<<"\n";
c%=5;
}
if(c>=1)
{
cout<<"1原ㄉ淺前:"<<c/1<<"個"<<"\n";
c%=1;
cout<<"ㄅ要淺前ㄉ畫,全部送偶也買擦"<<"\n";
}
cout<<"本胡務已偶ㄉ莉亦維攸仙,找玲神馬ㄉ材步給咧!"<<"\n";
cout<<"機械聲:謝謝光臨,歡迎再度光臨沒良心腦殘機器找零系統"
<<"\n";
fin:
system("pause");
return 0;
}
複製代碼
作者:
李大全
時間:
2014-11-29 11:06
#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;
goto re;
}
if(pay>price)
{
cout<<endl<<"需找客人"<<money<<"元"<<endl<<endl;
}
if(pay<price)
{
cout<<"少 "<<-money<<"元。幹!錢不夠還來我這裡買。"<<endl<<endl;
}
if(money>=1000)
{
cout<<"1000元鈔票"<<money/1000<<"張"<<endl;
money%=1000;
}
if(money>=500)
{
cout<<"五百元鈔票"<<money/500<<"張"<<endl;
money%=500;
}
if(money>=100)
{
cout<<"一百元鈔票"<<money/100<<"張"<<endl;
money%=100;
}
if(money>=50)
{
cout<<"五十元硬幣"<<money/50<<"枚"<<endl;
money%=50;
}
if(money>=10)
{
cout<<"十元硬幣"<<money/10<<"枚"<<endl;
money%=10;
}
if(money>=5)
{
cout<<"五元硬幣"<<money/5<<"枚"<<endl;
money%=5;
}
if(money>=1)
{
cout<<"一元硬幣"<<money<<"枚"<<endl;
}
if(money<=0)
{
cout<<"零元"<<money<<"幹馬的你不讓我賺多一點"<<endl;
goto re;
}
re:
cout<<endl;
system("pause");
return 0;
}
複製代碼
作者:
洪振庭
時間:
2014-11-29 11:08
#include <iostream>
#include <cstdlib>
using namespace std;
int main()
{
int p1,p2,mm;
cout<<"*** 智慧找零機 ***"<<endl<<endl;
cout<<"商品價為:";
cin>>p1;
cout<<"你付了多少?:";
cin>>p2;
mm=p2-p1;
cout<<"須找"<<mm<<"元"<<endl;
if(mm<=0)
{
cout<<"錢不夠!還要"<<-mm<<"元"<<endl;
}
else if(mm==0)
{
cout<<"銘謝惠顧"<<endl;
}
else
{
if(mm>=500)
{
cout<<"五百元鈔票"<<mm/500<<"張"<<endl;
mm%=500;
}
if(mm>=100)
{
cout<<"一百元鈔票"<<mm/100<<"張"<<endl;
mm%=100;
}
if(mm>=50)
{
cout<<"五十元硬幣"<<mm/50<<"枚"<<endl;
mm%=50;
}
if(mm>=10)
{
cout<<"十元鈔票"<<mm/10<<"枚"<<endl;
mm%=10;
}
if(mm>=5)
{
cout<<"五元鈔票"<<mm/5<<"枚"<<endl;
mm%=5;
}
if(mm>=1)
{
cout<<"一元鈔票"<<mm/1<<"枚"<<endl;
}
}
system("pause");
return 0;
}
複製代碼
作者:
梁和雋
時間:
2014-11-29 11:12
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
int price, pay, money;
cout<<"*** 智慧找零系統 ***"<<endl<<endl;
cout<<"請輸入商品價格: ";
cin>>price;
if(price<=0)
{
cout<<endl<<"?"<<endl<<endl;
goto end;
}
cout<<"付了多少錢: ";
cin>>pay;
if(pay<=0)
{
cout<<endl<<"?"<<endl<<endl;
goto end;
}
money=pay-price;
if(money<0)
{
cout<<endl<<"錢不夠! 差"<<-money<<"元!"<<endl<<endl;
}else if(money==0)
{
cout<<endl<<"剛剛好"<<endl<<endl;
else
{
cout<<endl<<"需找客人"<<money<<"元"<<endl<<endl;
if(money>=500)
{
cout<<"五百"<<money/500<<"張"<<endl;
money%=500; //money=money%500;
}
if(money>=100)
{
cout<<"一百"<<money/100<<"張"<<endl;
money%=100;
}
if(money>=50)
{
cout<<"五十元硬幣"<<money/50<<"枚"<<endl;
money%=50;
}
if(money>=10)
{
cout<<"十元"<<money/10<<"枚"<<endl;
money%=10;
}
if(money>=5)
{
cout<<"五元"<<money/5<<"枚"<<endl;
money%=5;
}
if(money>=1)
{
cout<<"一元"<<money<<"枚"<<endl;
}
cout<<endl;
}
end:
system("pause");
return 0;
}
複製代碼
歡迎光臨 種子論壇 | 高雄市資訊培育協會學員討論區 (http://seed.istak.org.tw/)
Powered by Discuz! 7.2