Hey guys! I'm brand new to C and I'm having a hell of a hard time so far. I'm currently writing one of my first programs for my class and I'm completely suck. We're supposed to write a cash back program where a user enters a dollar amount up to $100 and they get their change back in twenties, tens, fives, ones, quarters, dimes, nickels, and pennies.
The amount entered has to be a double and I don't understand how I can divide a double by another double, and then take the remainder and use it for another dollar value.
Any help is MUCH appreciated! My current code is below. Thanks!
Code:
#include <stdio.h>#include <stdlib.h>
int main()
{
float twenties;
float twentiesRemainder;
float tens;
float fives = 5;
float ones = 1;
float quarter = .25;
float dime = .10;
float nickel = .05;
float penny = .01;
double dollarEnt;
/*Get the total input amount*/
printf("Please enter a dollar amount up to 100: ");
scanf("%lf", &dollarEnt);
twenties = (dollarEnt/(20));
if (twenties>=1)
printf("%.0lf twenties", twenties);
tens = (twenties/(10));
if (tens>=1)
printf("%.2lf tens", tens);
if (fives>=1)
printf("%.2lf", fives);
if (ones>=1)
printf("%.2lf", ones);
if (quarter>=1)
printf("%.2lf", quarter);
if (dime>=1)
printf("%.2lf", dime);
if (nickel>=1)
printf("%.2lf", nickel);
if (penny>=1)
printf("%.2lf", penny);
system("Pause");
return 0;
}