I can't seem to figure out whats wrong with my code, but I'm receiving incorrect values for simple inputs like 1 or 2 but correct inputs for .41. If someone could help me out It'd be greatly appreciated!
This is my code:
#include <stdio.h>
#include <cs50.h>
#include <math.h>
int main(void)
{
//Establish Variables
float amount_owed;
int c = 0;
//Get Valid Input from User
do
{
amount_owed = get_float ("Change Owed: ");
} while (amount_owed <= 0);
//Check for quarters, mark # of quarters that can be used, subtract value from original amount_owed
do
{
(c++);
(amount_owed = amount_owed - .25);
} while (amount_owed >= .25);
//Check for dimes, mark # of dimes that can be used, subtract value from original amount_owed
do
{
(c++);
(amount_owed = amount_owed - .1);
} while ((amount_owed >= .1) && (amount_owed < .25));
//Check for Nickels, mark $ of nickels that can be used, subtract value from original amount_owed
do
{
(c++);
(amount_owed = amount_owed - .05);
} while ((amount_owed >= .05) && (amount_owed < .1));
//Check for Pennies, mark # of pennis that can be used, subtract value from original amount_owed
do
{
(c++);
(amount_owed = amount_owed - .01);
} while ((amount_owed >= .01) && (amount_owed < .05));
//Print Number of Minimum number of coins that can be used
{
if (amount_owed == 0)
;
printf("%d\n", c);
}
}
转载于:https://stackoverflow.com/questions/53147814/cash-c-expected-18-n-not-22-n