【发布时间】:2016-09-24 03:07:43
【问题描述】:
如果之前有人问过这个问题,我深表歉意。我环顾四周,找不到解决方案,我是 C 新手。 我知道我无法从浮点数中获得 %。如果我使用 2 个浮点数,我如何能够捕捉到这个数学的其余部分?
#include <cs50.h>
#include <stdio.h>
#include <ctype.h>
#include <math.h>
/*
** Always use the largest coin possible
** keep track of coins used
** Print the final amount of coins
*/
int main (void)
{
float change;
int counter = 0;
int division;
//float rem;
float quarter = 0.25;
//float quarter = 0.25, dime = 0.10, nickel = 0.05, penny = 0.01;
/* Prompt user for an amont of change*/
do{
printf("How much do we owe you in change? ");
change = GetFloat();
}
while (change <= 0);
if (change >= quarter)
{
division = (change / quarter);
counter += division;
//change = (int)(change % quarter);
printf("change: %.2f\n", change);
printf("counter: %d\n ", counter);
}
return (0);
}
【问题讨论】:
标签: c module floating-point cs50