level 6
baltu
楼主
原题目是输入一个金额,找零钱,有面值10,5,1,0.5,0.1元
#include <iostream>
using namespace std;
int main()
{
int c1,c2,c3,c4,c5; //5种面值
float x; //任意输入的值类型
cout<<"please write down the amount"<<endl;
cin>>x; //输入数值
c1=x/10; //找的10元有这么多张,不知道要不要加强制转换即c1=(int)x/10
c2=x%10/5; //将剩下的钱继续找
c3=x%10%5/1;
c4=10*(x%10%5%1)/5; //是不是不能直接除以0.5元取整
c5=10*(x%10%5%1)%5/1; //计算时先算括号的,再乘以10怎么错了
cout<<"10$ have "<<c1<<endl;
cout<<"5$ have "<<c2<<endl;
cout<<"1$ have "<<c3<<endl;
cout<<"0.5$ have "<<c4<<endl;
cout<<"0.1$ have "<<c5<<endl;
return 0; //是不是return 0就可以用void
}I
2013年09月17日 04点09分
1
#include <iostream>
using namespace std;
int main()
{
int c1,c2,c3,c4,c5; //5种面值
float x; //任意输入的值类型
cout<<"please write down the amount"<<endl;
cin>>x; //输入数值
c1=x/10; //找的10元有这么多张,不知道要不要加强制转换即c1=(int)x/10
c2=x%10/5; //将剩下的钱继续找
c3=x%10%5/1;
c4=10*(x%10%5%1)/5; //是不是不能直接除以0.5元取整
c5=10*(x%10%5%1)%5/1; //计算时先算括号的,再乘以10怎么错了
cout<<"10$ have "<<c1<<endl;
cout<<"5$ have "<<c2<<endl;
cout<<"1$ have "<<c3<<endl;
cout<<"0.5$ have "<<c4<<endl;
cout<<"0.1$ have "<<c5<<endl;
return 0; //是不是return 0就可以用void
}I