i'm actually at a loss as to what to do to fix this... here is my code. as expected the dollars portion works fine... so if you want an idea of how it work just enter like 21.00 and 25.00
below is my main.c, followed by functions.c and functions.h
Code:
/****************************************************************************
*Luke Stanton *
*October 12, 2008 *
*Programming Assignment 5 *
*Description:
****************************************************************************/
#include "functions.h"
int main (void)
{
double price = 0.0;
double paid = 0.0;
double coin_change = 0.0;
double total_change = 0.0;
int dollar_change = 0;
int hundred_bill = 0;
int fifty_bill = 0;
int twenty_bill = 0;
int ten_bill = 0;
int five_bill = 0;
int one_bill = 0;
int quarter = 0;
int dime = 0;
int nickel = 0;
int penny = 0;
//welcome screen
welcome_screen();
//prompts the user for the price and amount paid
prompt_input(&price, &paid);
//welcome screen
welcome_screen();
//determines the total change owed
total_change = paid - price;
// truncates(removes cents from amount) the amounts so the dollar
// change can be simplified and addressed
(int)dollar_change = total_change;
// removes the dollars so just the cents can be addressed
coin_change = total_change - dollar_change;
// finds dollar count in change
get_dollar_count(&hundred_bill, &fifty_bill, &twenty_bill, &ten_bill, &five_bill, &one_bill, &dollar_change);
// finds coin count in change
get_coin_count(&quarter, &dime, &nickel, &penny, &coin_change);
// Prints out the total change due
printf("Total: %.2lf\n", price);
printf("Paid: %.2lf\n", paid);
printf("Change: %.2lf\n\n", total_change);
// Displays what bills are due
printf(" Dollar bills: %d\n Five dollar bills: %d\n Ten dollar bills: %d\n Twenty dollar bills: %d\n Fifty dollar bills: %d\n One hundred dollar bills: %d\n\n",
one_bill, five_bill, ten_bill, twenty_bill, fifty_bill, hundred_bill);
// Displays what coins are due
printf(" Pennies: %d\n Nickels: %d\n Dimes: %d\n Quarters: %d\n\n",
penny, nickel, dime, quarter);
return 0;
}
Code:
//FUNCTIONS.C
#include "functions.h"
int welcome_screen(void)
{
system("cls");
printf(" ________________________________\n");
printf(" |$5 $5|\n");
printf(" | /-------\\ |\n");
printf(" | --- /---------\\ --- |\n");
printf(" | WELCOME-TO-CHANGE-CALCULATOR |\n");
printf(" | --- \\---------/ --- |\n");
printf(" | \\-------/ |\n");
printf(" |$5____________________________$5|\n\n");
return 0;
}
double prompt_input(double *price, double *paid)
{
printf("\n\n\nPlease enter the price of total purchase:");
scanf("%lf", &*price);
printf("\nPlease enter the amount paid by the customer:");
scanf("%lf", &*paid);
system("cls");
return 0;
}
int get_dollar_count(int *hundred_bill, int *fifty_bill, int *twenty_bill, int *ten_bill, int *five_bill, int *one_bill, int *dollar_change)
{
if (*dollar_change >= HUNDRED)
{
*hundred_bill = *hundred_bill + 1;
*dollar_change = *dollar_change - HUNDRED;
}
if (*dollar_change >= FIFTY)
{
*fifty_bill = *fifty_bill + 1;
*dollar_change = *dollar_change - FIFTY;
}
if (*dollar_change >= TWENTY)
{
*twenty_bill = *twenty_bill + 1;
*dollar_change = *dollar_change - TWENTY;
}
if (*dollar_change >= TEN)
{
*ten_bill = *ten_bill + 1;
*dollar_change = *dollar_change - TEN;
}
if (*dollar_change >= FIVE)
{
*five_bill = *five_bill + 1;
*dollar_change = *dollar_change - FIVE;
}
while (*dollar_change != 0)
{
*one_bill = *one_bill + 1;
*dollar_change = *dollar_change - DOLLAR;
}
return 0;
}
int get_coin_count(int *quarter, int *dime, int *nickel, int *penny, double *coin_change)
{
while(*coin_change >= QUARTER)
{
*quarter = *quarter + 1;
*coin_change = *coin_change - QUARTER;
}
while(*coin_change >= DIME)
{
*dime = *dime + 1;
*coin_change = *coin_change - DIME;
}
if (*coin_change >= NICKEL)
{
*nickel = *nickel + 1;
*coin_change = *coin_change - NICKEL;
}
while (*coin_change != 0)
{
*penny = *penny + 1;
*coin_change = *coin_change - PENNY;
}
return 0;
}
Code:
//FUNCTIONS.H
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#define DOLLAR 1
#define FIVE 5
#define TEN 10
#define TWENTY 20
#define FIFTY 50
#define HUNDRED 100
#define PENNY .01
#define NICKEL .05
#define DIME .10
#define QUARTER .25
int welcome_screen(void);
double prompt_input(double *price, double *paid);
int get_dollar_count(int *hundred_bill, int *fifty_bill, int *twenty_bill, int *ten_bill, int *five_bill, int *one_bill, int *dollar_change);
int get_coin_count(int *quarter, int *dime, int *nickel, int *penny, double *coin_change);