Untitled

mail@pastecode.io avatar
unknown
plain_text
6 months ago
2.7 kB
62
Indexable
Never
#include <cs50.h>
#include <stdio.h>
int mod(int x, int y);
int div(int x, int y);


int main(void)
{
    int coins = 0;
    int i = 0;
    int quarter = 0;
    int j = 0;
    int dime = 0;
    int k = 0;
    int nickle = 0;
    int l = 0;
    int pennies = 0;
    int m;
    // all_amount_in_cents


    do{
        m = get_int("input the amount: ");
        if (m<50){
            printf("Input correct amount more than 50c\n");
        }
    } while (m <50);

    int c = m - 50;

    printf("Change owed %i cents\n", c);
    printf("print %i\n", coins);
    int b = 25;


    if (mod(c, 25) == 0)
    {
        printf("only %i - 25c coin/s needed \n", div(c, 25));
        coins += div(c,25);
    }
    else if (mod(c, 25) != 0)
    {
        i = div(c, 25);
        quarter = c - (i * 25);
        printf("The number of cents remaining after using: %i -> 25cent coin is: %i cents\n", i, quarter);
        coins += i;
        if (mod(quarter, 10) == 0)
        {
            printf("only %i - 10c coin/s needed \n",div(quarter,10));
            coins += div(quarter,10);
        }

        else if (mod(quarter, 10) != 0)
        {
            j = div(quarter, 10);
            dime = quarter - (j * 10);
           printf("The number of cents remaining after using: %i -> 10cent coin, is: %i cents\n",j,dime);
           coins += j;
            //quarter, dime, nickel, pennies

            if (mod(dime, 5) == 0)
            {
                printf("only %i - 5c coin/s needed \n",div(dime,5));
                coins += div(dime,5);
            }
            else if (mod(dime, 5) != 0)
            {
                k = div(dime, 5);
                nickle = dime - (k * 5);
                printf("The number of cents remaining after using: %i -> 5cent coin, is: %i cents\n",k,nickle);
                coins+=k;
                // quarter, dime, nickel, pennies
                // pennies
                 if (mod(nickle, 1) == 0)
                    {
                        printf("only %i - 1c coin/s needed \n", div(nickle, 1));
                        coins+=div(nickle, 1);
                    }
                else if (mod(nickle, 1) != 0)
                    {
                        l = div(nickle, 1);
                        pennies = nickle - (l * 1);
                        printf("The number of cents remaining after using: %i -> 1cent coin, is: %i cents\n", l, pennies);
                        coins+=l;
                    }

            }
        }
    }
}

int mod(int x, int y)
{
    return x % y;
}

int div(int x, int y)
{
    return x / y;
}
Leave a Comment