lundi 30 janvier 2017

Cash Register with Dollars and Quarters output in C

I have to program a cash register that has a user input the amount to be paid and it has to output the amount to be paid and then output the number of loonies required to pay the amount followed by the number of quarters required to pay the amount, etc... I've managed to out the amount to be paid as well as the number of loonies required by truncating the amount to be paid, but I'm at a loss as to how to solve the number of quarters, dimes, nickels and pennies required to pay. Here's my code:

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

int main (void)

{
        double cost;
        int loonies, quarters;
        float loonreq;


        printf ("Please enter the amount to be paid: ");
        scanf ("%lf", &cost);

        printf ("Change Due: $ %.2f\n", cost);

        loonies = cost;
        printf ("Loonies required: %d, ", loonies);

        loonreq = cost - loonies;
        printf ("balance owing: $ %.2f\n", loonreq);

        return 0;
}

Aucun commentaire:

Enregistrer un commentaire