標題:
硬弊換紙鈔
[打印本頁]
作者:
tonyh
時間:
2011-12-10 17:04
標題:
硬弊換紙鈔
本帖最後由 tonyh 於 2011-12-10 17:32 編輯
讓使用者輸入想兌換的硬幣金額, 電腦回應:
能兌換成1000元鈔票幾張, 500元鈔票幾張, 100元鈔票幾張, 以及剩餘零錢多少元.
#include<iostream>
using namespace std;
int main()
{
int sum, a[4]; //a[0] a[1] a[2] a[3]
cout<<"請輸入您想兌換的硬幣: ";
cin>>sum;
cout<<"硬幣"<<sum<<"元可兌換..."<<endl;
a[0]=sum/1000;
sum=sum%1000;
a[1]=sum/500;
sum=sum%500;
a[2]=sum/100;
sum=sum%100;
a[3]=sum;
cout<<"一千元鈔票"<<a[0]<<"張, 五百元鈔票"<<a[1]<<"張, 一百元鈔票"<<a[2]
<<"張, 剩餘零錢"<<a[3]<<"元"<<endl;
system("pause");
return 0;
}
複製代碼
作者:
t2364705
時間:
2011-12-10 17:20
#include<iostream>
using namespace std;
int main()
{
int sum,a[4];
cout<<"請輸入您想換算的硬幣: ";
cin>>sum;
cout<<sum<<"硬幣可換算為..." <<endl;
a[0]=sum/1000;
sum=sum%1000;
a[1]=sum/500;
sum=sum%500;
a[2]=sum/100;
a[3]=sum%100;
cout<<a[0]<<"張一千元, "<<a[1]<<"張五百元, "<<a[2]<<"張一百元, "<<a[3]<<"元, "<<endl;
system("pause");
return 0;
}
複製代碼
作者:
尤泓鈞
時間:
2011-12-10 17:24
#include<iostream>
using namespace std;
int main()
{
int sum,a[14];
cout<<"請輸入你想換算的硬幣:";
cin>>sum;
cout<<sum<<"可換紙鈔算為..."<<endl;
a[0]=sum/1000;
sum=sum%1000;
a[1]=sum/500;
sum=sum%500;
a[2]=sum/100;
sum=sum%100;
a[3]=sum/50;
sum=sum%50;
a[4]=sum/10;
sum=sum%10;
a[5]=sum/5;
sum=sum%5;
a[6]=sum/1;
sum=sum%1;
cout<<a[0]<<"張一千元,"<<a[1]<<"張五百元,"<<a[2]<<"張一百元,"<<a[3]<<"個五十元,"<<a[4]<<"個十元,"<<a[5]<<"個五元,"<<a[6]<<"個一元."<<endl;
system("pause");
return 0;
}
複製代碼
作者:
劉漢文
時間:
2011-12-10 17:30
#include<iostream>
using namespace std;
int main()
{
int sum,a[4];
cout<<"請輸入您想換算的硬幣: ";
cin>>sum;
cout<<sum<<"硬幣可換..." <<endl;
a[1]=sum/1000;
sum=sum%1000;
a[2]=sum/500;
sum=sum%500;
a[3]=sum/100;
a[4]=sum%100;
cout<<a[1]<<"張一千元 & "<<a[2]<<"張五百元 & "<<a[3]<<"張一百元 & "<<"剩下"<<a[4]<<"元. "<<endl;
system("pause");
return 0;
}
複製代碼
作者:
t8155745
時間:
2011-12-10 17:31
#include <iostream>
using namespace std;
int main()
{
int sum, a[4];
cout<<"請輸入您想換算的硬幣:";
cin>>sum;
cout<<sum<<"硬幣可換質為..."<<endl;
a[0]=sum/1000;
sum=sum%1000;
a[1]=sum/500;
sum=sum%500;
a[2]=sum/100;
sum=sum%100;
cout<<a[0]<<"張千元, "<<a[1]<<"張5百元, "<<a[2]<<"張1百元, "
<<"和"<<sum<<"元硬幣."<<endl;
system("pause");
return 0;
}
複製代碼
作者:
t3742238
時間:
2011-12-10 17:33
本帖最後由 t3742238 於 2011-12-10 19:40 編輯
#include<iostream>
using namespace std;
int main()
{
int sum, a[8];
cout<<"請輸入您想兌換的硬幣: ";
cin>>sum;
cout<<"硬幣"<<sum<<"元可兌換..."<<endl;
a[0]=sum/2000;
sum=sum%2000;
a[1]=sum/1000;
sum=sum%1000;
a[2]=sum/200;
sum=sum%200;
a[3]=sum/100;
sum=sum%100;
a[4]=sum/50;
sum=sum%50;
a[5]=sum/10;
sum=sum%10;
a[6]=sum/5;
sum=sum%5;
a[7]=sum/1;
sum=sum%1;
cout<<"兩千元鈔票"<<a[0]<<"張, 一千元鈔票"<<a[1]<<"張, 兩百元鈔票"<<a[2]
<<"張, 一百元鈔票"<<a[3]<<"張"<<" 五十元硬幣"<<a[4]<<"個"
<<"十元硬幣"<<a[5]<<"個"<<" 五元硬幣"<<a[6]<<"個"
<<"一元硬幣"<<a[7]<<"個"<<endl;
system("pause");
return 0;
}
複製代碼
歡迎光臨 種子論壇 | 高雄市資訊培育協會學員討論區 (http://istak.org.tw/seed/)
Powered by Discuz! 7.2