The output is not being rounded off: It doesn't count the cents value if you input a dollar in decimal. if it's $45.67, it only counts change for $45. Also, output comes back 0 if the input is negative, while I want the question to be repeated if the input is negative..
e.g., input = 0.67, output = 0 (expected 6).... input = 7.36, output = 3 (not counting cents).... input = 4.20, output = 4 (expected 18).... Also, input 23 gives output 5 instead of 93.... And it rejects negative input like -2, whereas I want it to loop back to the question.
Here is my code:
#include <stdio.h>
#include <cs50.h>
#include <math.h>
void greedyAlgorithm(int n); //Define the function
int main(void)
{
float dollars=get_float("Change owed:"); // Ask for change
int n=round(dollars*100);
greedyAlgorithm(dollars); // Run the greedy algorithm
return 0;
}
void greedyAlgorithm(int n)
{
int A=0, B=0, C=0, D=0, count=A+B+C+D;
//total number of quarters ($0.25)
while(n>=25)
{
count++, A++;
n=n-25;
}
..........................
//repeat with each value of coins
printf("%d\n", count);
}