:rolleyes:
This is a program where the user enters how much they owe, then they enter how much they are gonna pay, like (30 dollars for a $25.63 amount), and their change is calculated back to them in ten dollar bills, five dollar bills, one dollar bills, quarters, dimes, nickels, and pennies.

My instructor hinted us to use the mod operator but i found that '%' does not work with doubles or floats. So i am left with no clue on how to program this thing and i dont want to get an F, because so far ive been gettings A's. Its just this darn mod operator is so stubborn. thanks for any help i can get.

here is the code i have.

#include <stdio.h>              /* includes stdio.h i/o */

void pause(void);               /* declares function */

int main(void)
{
    double due, given, bal = 0;     /* sets double float variables */
    double tens, fives, ones, quarters, dimes, nickels, pennies = 0;
    printf("\n\n\tHow much do you owe?\n\n\t\tAmount : ");
            /* asks for debt */
    scanf("%lf", &due);         /* accepts user's input */
    printf("\n\n\tHow much will you pay?\n\n\t\tAmount : ");
            /* asks user how much they will give to pay for the amount */
    scanf("%lf", &given);       /* accepts user's input */
    bal = given - due;          /* calculates the user's change */
    printf("\n\nAmount Due     = $%.2lf", due);        /* displays transaction info */
    printf("\n\nAmount Given   = $%.2lf", given);
    printf("\n\nAmount Balance = $%.2lf", bal);
    printf("\n\n\tHere is your Change.");
    if((bal / 10) >= 1)         /* if can be divided by bill, determines
                                    how many bills */
    {
        tens = bal / 10;
        bal = bal % 10;        
    }  
    if((bal / 5) >= 1)         /* if can be divided by bill, determines
                                    how many bills */
    {
        fives = bal / 5;
        bal = bal % 5;
    }
    if((bal / 1) >= 1)         /* if can be divided by bill, determines
                                    how many bills */
    {
        ones = bal / 1;
        bal = bal % 1;
    }
    if((bal / .25) >= 1)         /* if can be divided by coin, determines
                                    how many coins */
    {
        quarters = bal / .25;
        bal = bal % .25;
    }  
    if((bal / .10) >= 1)         /* if can be divided by coin, determines
                                    how many coins */
    {
        dimes = bal / .10;
        bal = bal % .10;
    }    
    if((bal / .05) >= 1)         /* if can be divided by coin, determines
                                    how many coins */
    {
        nickels = bal / .05;
        bal = bal % .05;
    }
    if((bal / .01) >= 1)         /* if can be divided by coin, determines
                                    how many coins */
    {
        pennies = bal / .01;
        bal = bal % .01;
    }     
    printf("\nTens     = %d", tens);         /* prints change resulsts */
    printf("\nFives    = %d", fives);
    printf("\nOnes     = %d", ones);
    printf("\nQuarters = %d", quarters);
    printf("\nDimes    = %d", dimes);
    printf("\nNickels  = %d", nickels);
    printf("\nPennies  = %d", pennies);
    pause();                    /* pauses */
    return (0);
}
void pause(void)                /* tells what pause does */
{
    char ch;                    /* sets character variable */
    printf("\n\nPress \'Enter\' to exit.");
    scanf("%c", &ch);           /* waits for 'enter' key */
    scanf("%c", &ch);
}

>Its just this darn mod operator is so stubborn.
When working with money, it's best to use integers because floating-point has accuracy issues. However, if you really want to use floating-point, the standard library supports the fmod function. fmod will perform modulus on two floating-point values.

thanks, what does fmod look like? do i just type "fmod" or does it have its own symbol?

double fmod(double x, double y) is a function, so you have to rewrite your code a little. It returns the remainder of the division x / y. Make sure to #include <math.h>

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.