標題:
智慧找零系統 (二)
[打印本頁]
作者:
tonyh
時間:
2015-6-12 19:46
標題:
智慧找零系統 (二)
本帖最後由 tonyh 於 2016-5-30 12:34 編輯
設計一個更聰明的智慧找零系統, 包括客人付的錢
不足
,
剛好
, 或
任何
可能發生的狀況.
[attach]1275[/attach]
[attach]1276[/attach]
[attach]1277[/attach]
[attach]1278[/attach]
作者:
沈子耕
時間:
2015-6-12 20:26
#include<iostream>
#include<cstdlib>
using namespace std;
int main(){
re:
int price, pay, money;
cout<<"請輸入商品價格: ";
cin>>price;
cout<<"客人付了多少錢: ";
cin>>pay;
if(pay==price){
cout<<"付的錢剛剛好"<<endl<<endl;
}
else if(pay<price && pay>0){
cout<<"付的錢不夠,還差"<<price-pay<<"元"<<endl<<endl;
}
else if(pay==0){
cout<<"不付錢的澳客,滾!"<<endl<<endl;
}
else if(pay>=100*price){
cout<<"錢太多送我"<<endl<<endl;
}
else {
money = pay-price;
cout<<endl<<"需找客人 "<<money<<" 元"<<endl<<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/500<<"枚"<<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;
}
goto re;
system("pause");
return 0;
}
複製代碼
作者:
曾挺桂
時間:
2015-6-12 20:26
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
re:
int thing,pay,money;
cout<<"*** 智慧找零系統 ***"<<endl<<endl;
cout<<"請輸入商品價格: ";
cin>>thing;
cout<<"客人付了多少錢: ";
cin>>pay;
money=pay-thing;
cout<<endl<<"需找客人"<<money<<"元"<<endl<<endl;
if(money<0)
{
cout<<"錯誤! #$%ˊ79@"<<endl;
}
else if(money=0)
{
cout<<"你不錯嘛,省了我找錢的力氣"<<endl;
}
else if(money>=1000)
{
cout<<"不要以為錢多就能耍智缺!給我滾!"<<endl;
}
else if(money>=500)
{
cout<<"五百元鈔票"<<money/500<<"張"<<endl;
money%=500;
}
else if(money>=100)
{
cout<<"一百元鈔票"<<money/100<<"張"<<endl;
money%=100;
}
else if(money>=50)
{
cout<<"五十元硬幣"<<money/50<<"枚"<<endl;
money%=50;
}
else if(money>=10)
{
cout<<"十元硬幣"<<money/10<<"枚"<<endl;
money%=10;
}
else if(money>=5)
{
cout<<"五元硬幣"<<money/5<<"枚"<<endl;
money%=5;
}
else if(money>0)
{
cout<<"一元硬幣"<<money<<"枚"<<endl;
}
goto re;
system("pause");
return 0;
}
複製代碼
作者:
陳思惟
時間:
2015-6-12 20:43
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
cout<<"*** 智慧找零系統 ***"<<endl<<endl;
string x;
int y,z;
cout<<"輸入使用者名稱: ";
cin>>x;
c:
cout<<"輸入密碼: ";
cin>>y;
if(y==0000)
{
b:
cout<<"模式選擇";
cout<<"(1) 進入找零系統,(2) 離開";
cin>>z;
if(z==1)
{
goto re;
}
if else(z==2)
{
goto end;
}
else
{
cout<<"錯誤";
goto b;
}
else
{
cout<<"錯誤";
goto c;
}
re:
int price,pay,money1,money2;
cout<<"請輸入商品價格: ";
cin>>price;
cout<<"客人付了多少錢: ";
cin>>pay;
money1=pay-price;
money2=price-pay;
if(pay>10000000)
{
cout<<endl<<"錢太多,送我吧!!!"<<"\a\a\a"<<"\a\a\a"<<money2<<"元"<<endl<<endl;
}
if(pay==0)
{
cout<<endl<<"不付錢,讓你電腦當掉!!!"<<endl<<endl;
a;
cout<<"\a";
goto a;
}
if(pay<price)
{
cout<<endl<<"付的錢不夠,警告你,先不讓你電腦當機,需再付 "<<"\a\a\a"<<money2<<"元"<<endl<<endl;
}
if(money==0)
{
cout<<endl<<"付的錢剛剛好!!!"<<endl<<endl;
}
if(pay>price)
{
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>0)
cout<<"一元硬幣"<<money<<"枚"<<endl;
goto re;
end:
system("pause");
return 0;
}
複製代碼
作者:
曾挺桂
時間:
2015-6-12 21:16
#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>=10000)
{
cout<<"你錢太多啊!"<<endl;
}
else if(money<0)
{
cout<<"滾去一旁吧!"<<endl;
}
else if(money==0)
{
cout<<"你不錯!讓我省了找錢的時間"<<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>0)
cout<<"一元硬幣"<<money<<"枚"<<endl;
}
cout<<endl<<endl;
system("pause");
return 0;
}
複製代碼
作者:
陳思惟
時間:
2015-6-12 21:20
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
cout<<"*** 智慧找零系統 ***"<<endl<<endl;
string x,y,pass="0000";
int z,w;
cout<<"輸入使用者名稱: ";
cin>>x;
d:
cout<<"模式選擇";
cout<<"(1) 進入,(2) 離開";
cin>>w;
if(w==1)
{
goto c;
}
else if(w==2)
{
goto end;
}
else
{
cout<<"錯誤";
goto d;
}
c:
cout<<"輸入密碼: ";
cin>>y;
if(y==pass)
{
b:
cout<<"模式選擇";
cout<<"(1) 進入找零系統,(2) 離開";
cin>>z;
if(z==1)
{
goto re;
}
else if(z==2)
{
goto end;
}
else
{
cout<<"錯誤";
goto b;
}
}
else
{
cout<<"錯誤";
goto c;
}
re:
cout<<"使用者: "<<x<<endl;
int price,pay,money1,money2;
cout<<"請輸入商品價格: ";
cin>>price;
cout<<"客人付了多少錢: ";
cin>>pay;
money1=pay-price;
money2=price-pay;
if(pay>10000000)
{
cout<<endl<<"錢太多,送我吧!!!"<<"\a\a\a"<<"\a\a\a"<<money2<<"元"<<endl<<endl;
}
if(pay==0)
{
cout<<endl<<"不付錢,讓你電腦當掉!!!"<<endl<<endl;
a:
cout<<"\a\a\a";
goto a;
}
if(pay<price)
{
cout<<endl<<"付的錢不夠,警告你,先不讓你電腦當機,需再付 "<<"\a\a\a"<<money2<<"元"<<endl<<endl;
}
if(money1==0)
{
cout<<endl<<"付的錢剛剛好!!!"<<endl<<endl;
}
if(pay>price)
{
cout<<endl<<"需找客人"<<money1<<"元"<<endl<<endl;
}
if(money1>=500)
{
cout<<"五百元鈔票"<<money1/500<<"張"<<endl;
money1%=500; //money=money%500;
}
if(money1>=100)
{
cout<<"一百元鈔票"<<money1/100<<"張"<<endl;
money1%=100;
}
if(money1>=50)
{
cout<<"五十元硬幣"<<money1/50<<"枚"<<endl;
money1%=50;
}
if(money1>=10)
{
cout<<"十元硬幣"<<money1/10<<"枚"<<endl;
money1%=10;
}
if(money1>=5)
{
cout<<"五元硬幣"<<money1/5<<"枚"<<endl;
money1%=5;
}
if(money1>0)
cout<<"一元硬幣"<<money1<<"枚"<<endl;
goto re;
end:
system("pause");
return 0;
}
複製代碼
歡迎光臨 種子論壇 | 高雄市資訊培育協會學員討論區 (http://seed.istak.org.tw/)
Powered by Discuz! 7.2