標題:
[作業] 智慧找零系統 進階練習
[打印本頁]
作者:
tonyh
時間:
2011-11-12 17:35
標題:
[作業] 智慧找零系統 進階練習
本帖最後由 tonyh 於 2011-11-19 16:28 編輯
設計一個更聰明的智慧找零系統, 包括客人付的錢不足, 剛好, 或任何可能發生的其他情況.
#include<iostream>
using namespace std;
int main()
{
int price, money;
cout<<"***智慧找零系統***"<<endl;
cout<<"請輸入商品價格: ";
cin>>price;
cout<<"請輸入客人付了多少錢: ";
cin>>money;
if(price>money)
{
cout<<"客人你付的錢不夠喔, 還差"
<<price-money<<"元"<<endl;
}
if(price==money)
{
cout<<"剛剛好! 謝謝惠顧!"<<endl;
}
if(price<money)
{
cout<<"總共需找客人"<<money-price<<"元"<<endl;
money=money-price;
int a, b, c, d, e;
if(money>=500)
{
a=money/500;
money=money%500;
cout<<"500元鈔票"<<a<<"張"<<endl;
}
if(money>=100)
{
b=money/100;
money=money%100;
cout<<"100元鈔票"<<b<<"張"<<endl;
}
if(money>=50)
{
c=money/50;
money=money%50;
cout<<"50元硬幣"<<c<<"枚"<<endl;
}
if(money>=10)
{
d=money/10;
money=money%10;
cout<<"10元硬幣"<<d<<"枚"<<endl;
}
if(money>=5)
{
e=money/5;
money=money%5;
cout<<"5元硬幣"<<e<<"枚"<<endl;
}
if(money>=1)
{
cout<<"1元硬幣"<<money<<"枚"<<endl;
}
}
cout<<endl;
system("pause");
return 0;
}
複製代碼
作者:
t8155745
時間:
2011-11-12 17:40
本帖最後由 t8155745 於 2012-3-17 17:25 編輯
[code][code]#include <iostream>
using namespace std;
int main()
{
int price,money;
cout<<"%%%智慧錢找零機%%%"<<endl;
cout<<"請輸入商品價格:";
cin>>price;
cout<<"請輸入客人付了多少錢:";
cin>>money;
cout<<"需找客人:"<<money-price<<"元"<<endl;
money=money-price;
int a,b,c,d,e;
if(money>=500)
{
a=money/500;
money=money%500;
cout<<"500元鈔票"<<a<<"張, " ;
}
if(money>=100)
{
b=money/100;
money=money%100;
cout<<"100鈔票"<<b<<"張, ";
}
if(money>=50)
{
c=money/50;
money=money%50;
cout<<"50硬幣"<<c<<"張, ";
}
if(money>=10)
{
d=money/10;
money=money%10;
cout<<"10硬幣"<<d<<"枚, ";
}
if(money>=5)
{
e=money/5;
money=money%5;
cout<<"5硬幣"<<e<<"枚, ";
}
if(money>=1)
{
cout<<"1硬幣"<<money<<"枚, ";
} system("pause");
return 0;
}
複製代碼
[/code][/code]
作者:
t3742238
時間:
2011-11-19 10:19
本帖最後由 t3742238 於 2011-11-19 16:19 編輯
#include <iostream>
using namespace std;
int main()
{
int price,money;
cout<<"***智慧找零機***"<<endl;
cout<<"請輸入商品價格:";
cin>>price;
cout<<"請輸入客人付了多少錢:";
cin>>money;
if(price>money)
{
cout<<"你的錢不夠, 還差"<<price-money<<"元"<<endl;
}
if(price=money)
{
cout<<"謝謝光臨"<<endl;
}
cout<<"需找客人:"<<money-price<<"元";
money=money-price;
int a,b,c,d,e;
if(money>=500)
{
a=money/500;
money=money%500;
cout<<"500元鈔票"<<a<<"張";
}if(money>=100)
{
b=money/100;
money=money%100;
cout<<"100鈔票"<<b<<"張";
}if(money>=50)
{
c=money/50;
money=money%50;
cout<<"50鈔票"<<c<<"張";
}if(money>=10)
{
d=money/10;
money=money%10;
cout<<"10硬幣"<<d<<"枚";
}if(money>=5)
{
e=money/5;
money=money%5;
cout<<"5硬幣"<<e<<"枚";
}if(money>=1)
{
e=money/1;
money=money%1;
cout<<"1硬幣"<<money<<"枚";
}
system("pause");
return 0;
}
複製代碼
作者:
蔡昀佑
時間:
2011-11-19 11:21
using namespace std;
int main()
{
int price,money;
cout<<"☆智慧找零系統☆"<<endl;
cout<<"請輸入商品價格:";
cin>>price;
cout<<"請輸入客人付了多少錢:";
cin>>money;
cout<<"需找客人:"<<money-price<<"元";
money=money-price;
int a,b,c,d,e;
if(money>=500)
{
a=money/500;
money=money%500;
cout<<"500元鈔票"<<a<<"張";
}
if(money>=100)
{
b=money/100;
money=money%100;
cout<<"100鈔票"<<b<<"張";
}
if(money>=50)
{
c=money/50;
money=money%50;
cout<<"50鈔票"<<c<<"張";
}
if(money>=10)
{
d=money/10;
money=money%10;
cout<<"10硬幣"<<d<<"枚";
}
if(money>=5)
{
e=money/5;
money=money%5;
cout<<"5硬幣"<<e<<"枚";
}
if(money>=1)
{
cout<<"1硬幣"<<money<<"枚";
}
system("pause");
return 0;
}
複製代碼
作者:
劉漢文
時間:
2011-11-19 14:48
本帖最後由 劉漢文 於 2011-11-19 16:40 編輯
#include <iostream>
using namespace std;
int main()
{
int price,money;
cout<<"***智慧找零機***"<<endl;
cout<<"請輸入商品價格:";
cin>>price;
cout<<"請輸入客人付了多少錢:";
cin>>money;
if(price>money)
{
cout<<"錢不夠ㄜ 還差"<<price-money<<"元"<<endl;
}
if(price==money)
{
cout<<"謝謝惠顧 下次再來"<<endl;
}
if(price<money)
{
cout<<"需找客人:"<<money-price<<"元"<<endl;
money=money-price;
int a,b,c,d,e;
if(money>=500)
{
a=money/500;
money=money%500;
cout<<"500元鈔票"<<a<<"張"<<endl;
}if(money>=100)
{
b=money/100;
money=money%100;
cout<<"100鈔票"<<b<<"張"<<endl;
}if(money>=50)
{
c=money/50;
money=money%50;
cout<<"50鈔票"<<c<<"張"<<endl;
}if(money>=10)
{
d=money/10;
money=money%10;
cout<<"10硬幣"<<d<<"枚"<<endl;
}if(money>=5)
{
e=money/5;
money=money%5;
cout<<"5硬幣"<<e<<"枚"<<endl;
}if(money>=1)
{
cout<<"1元硬幣"<<money<<"枚"<<endl;
}
}
system("pause");
return 0;
}
複製代碼
作者:
t2364705
時間:
2011-11-19 16:40
#include<iostream>
using namespace std;
int main()
{
int price,money;
cout<<"***好玩的聰明的找零系統***";
cout<<"請輸入商品價格";
cin>>price;
cout<<"請輸入客人付了多少錢";
cin>>money;
if(money<price)
{
cout<<"您帶的錢不夠!!您差"<< price-money<<"元" ;
}else
{
cout<<"需要找客人的錢"<<money-price<<"元";
money=money-price;
int a,b,c,d,e;
if(money>=500)
{ a=money/500;
money=money%500;
cout<<"需要找客人500元的鈔票"<<a<<"張";
}
if(money>=100)
{
b=money/100;
money=money%100;
cout<<"100元鈔票"<<b<<"張"<<endl;
}
if(money>=50)
{
c=money/50;
money=money%50;
cout<<"50元硬幣"<<c<<"枚"<<endl;
}
if(money>=10)
{
d=money/10;
money=money%10;
cout<<"10元硬幣"<<d<<"枚"<<endl;
}
if(money>=5)
{
e=money/5;
money=money%5;
cout<<"5元硬幣"<<e<<"枚"<<endl;
}
if(money>=1)
{
cout<<"1元硬幣"<<money<<"枚"<<endl;
}
}
cout<<endl;
system("pause");
return 0;
}
複製代碼
作者:
t8155745
時間:
2011-11-19 16:46
本帖最後由 t8155745 於 2012-3-24 17:25 編輯
#include <iostream>
using namespace std;
int main()
{
int price,money;
cout<<"%%%噴錢找零機%%%"<<endl;
cout<<"請輸入商品價格:";
cin>>price;
cout<<"請輸入客人付了多少錢:";
cin>>money;
int a,b,c,d,e;
if(money<price)
{
cout<<"你帶的錢不夠,差了"<<price-money<<"元"<<endl;
}
if(money==price)
{
cout<<" 謝謝惠顧 "<<endl;
}
if(money>price)
{
cout<<"需噴客人:"<<money-price<<"元"<<endl;
money=money-price;
if(money>=500)
{
a=money/500;
money=money%500;
cout<<"500元鈔票"<<a<<"張"<<endl;
}
if(money>=100)
{
b=money/100;
money=money%100;
cout<<"100鈔票"<<b<<"張"<<endl;
}
if(money>=50)
{
c=money/50;
money=money%50;
cout<<"50鈔票"<<c<<"張"<<endl;
}
if(money>=10)
{
d=money/10;
money=money%10;
cout<<"10硬幣"<<d<<"枚"<<endl;
}
if(money>=5)
{
e=money/5;
money=money%5;
cout<<"5硬幣"<<e<<"枚"<<endl;
}
if(money>=1)
{
cout<<"1硬幣"<<money<<"枚"<<endl;
}
}
system("pause");
return 0;
}
複製代碼
作者:
尤泓鈞
時間:
2011-11-19 16:48
#include<iostream>
using namespace std;
int main()
{
int price, money;
cout<<"$$$自動找零系統$$$"<<endl;
cout<<"請輸入商品的價格: ";
cin>>price;
cout<<"請輸入客人付了多少錢: ";
cin>>money;
if(price>money)
{
cout<<"客人你付的錢不夠喔, 還差"
<<price-money<<"元"<<endl;
}
if(price==money)
{
cout<<"剛剛好! "<<endl;
}
if(price<money)
{
cout<<"需找客人"<<money-price<<"元"<<endl;
money=money-price;
int a, b, c, d, e;
if(money>=500)
{
a=money/500;
money=money%500;
cout<<"500元鈔票"<<a<<"張"<<endl;
}
if(money>=100)
{
b=money/100;
money=money%100;
cout<<"100元鈔票"<<b<<"張"<<endl;
}
if(money>=50)
{
c=money/50;
money=money%50;
cout<<"50元硬幣"<<c<<"枚"<<endl;
}
if(money>=10)
{
d=money/10;
money=money%10;
cout<<"10元硬幣"<<d<<"枚"<<endl;
}
if(money>=5)
{
e=money/5;
money=money%5;
cout<<"5元硬幣"<<e<<"枚"<<endl;
}
if(money>=1)
{
cout<<"1元硬幣"<<money<<"枚"<<endl;
}
}
cout<<endl;
system("pause");
return 0;
}
複製代碼
作者:
許逸瑋
時間:
2011-11-19 16:48
#include<iostream>
using namespace std;
int main()
{
int price,money;
cout<<"******智慧找零機******";
cout<<"請輸入商品價格";
cin>>price;
cout<<"請輸入客人付了多少錢";
cin>>money;
if(money<price)
{
cout<<"您帶的錢不夠!!您差"<< price-money<<"元" ;
}else
{
cout<<"需要找客人的錢"<<money-price<<"元";
money=money-price;
int a,b,c,d,e;
if(money>=500)
{ a=money/500;
money=money%500;
cout<<"需要找客人500元的鈔票"<<a<<"張";
}
if(money>=100)
{
b=money/100;
money=money%100;
cout<<"100元鈔票"<<b<<"張"<<endl;
}
if(money>=50)
{
c=money/50;
money=money%50;
cout<<"50元硬幣"<<c<<"枚"<<endl;
}
if(money>=10)
{
d=money/10;
money=money%10;
cout<<"10元硬幣"<<d<<"枚"<<endl;
}
if(money>=5)
{
e=money/5;
money=money%5;
cout<<"5元硬幣"<<e<<"枚"<<endl;
}
if(money>=1)
{
cout<<"1元硬幣"<<money<<"枚"<<endl;
}
}
cout<<endl;
system("pause");
return 0
複製代碼
歡迎光臨 種子論壇 | 高雄市資訊培育協會學員討論區 (http://istak.org.tw/seed/)
Powered by Discuz! 7.2