java将五元换成1元5角_C,一个代码来获得一笔钱转换成四分之一,硬币,镍币,便士[关闭]...
该代码无法正常工作!我是C和我的新任务,编写一个从用户获取 Value 的代码(金额),然后将其转换为“季度= 25美分,硬币= 10美分,镍币= 5美分,便士= 1美分”所以例如当我输入值7.47我应该得到29季度,2角钱,0镍,2便士等...我的问题是,我已经尝试了很多值,它工作得很好,但当我尝试的 Value 9.53我应该得到38个季度,0角钱,0个镍币和3个便士但是我得到38个季度,0角钱,0个镍币和2个便士当我尝试8.53时会发生同样的错误,但是当我尝试6.53,5.53 .4.53时它的工作原理好 !!我现在很困惑,所以请帮助!!
`#include
using namespace std;
int main()
{
double money, c_money, quarters, dimes, nickels, pennies, remainder; char response;
new_input:
cout << " Enter the amount of money to be converted : " << endl;
cin >> money;
while (money < 0)
{
cout << " Invalid input , please enter a non-negative value " << endl;
cin >> money;
}
c_money = money * 100;
quarters = (int)c_money / 25;
remainder = (int)c_money % 25;
dimes = (int)remainder / 10;
remainder = (int)remainder % 10;
nickels = (int)remainder /5;
remainder = (int)remainder % 5;
pennies = (int)remainder ;
cout << endl;
cout << " The amount of money entered could be represented as : " << endl;
cout << "*****************************************************" << endl;
cout <
cout <
cout <
cout <
cout << "Do you want to enter more values ?? type , y or n and press Enter ! " << endl;
cin >> response;
if (response == 'y')
{
goto new_input;
}
else { cout << " Thanks for using our app !! " << endl << endl; }
return 0;
}`