0

After I submitted my cash pset1, it returned three test cases(input of 1.6,23 and 4.2) giving the wrong output(7,92,18), also detailed in check50. But when I try the three test cases with my code, my code returned the correct answers to the prompt(3,0,2).

The check50 output is :( input of 1.6 yields output of 7 :( input of 23 yields output of 92 :( input of 4.2 yields output of 18

My code is as follows:

#include <stdio.h>
#include <cs50.h>
#include <math.h>

int main(void)
{
    float x, v;
    int c, a;
    int i = 0;
    do
    {
        //ask user for input
        x = get_float("owed change is: ");
        v = x - (int)x;
        c = round(v * 100);
    }
    while (x < 0);

    while (c >= 25)
    {
        c -= 25; 
        i++;    
    }


    while (c >= 10)
    {
        c -= 10; 
        i++;    
    }


    while (c >= 5)
    {
        c -= 5; 
        i++;    
    }


    i += c;
    printf("%i\n", i);
}
'''



1

This exercise expects the entire input amount to be converted to coin. It looks like the program will only convert the cents part of the input to coin. The check50 answers are correct. In the first test, input of 1.6, the cashier would give 6 quarters (.25) and 1 dime (.10), for a total of 7 coins.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .