1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
|
// Change_calculator.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <cmath>
int main(void)
{
const int twenty = 2000;
const short ten = 1000,five = 500,one = 100,quarter = 25,dime = 10,nickel = 5,penny = 1;
long double purchase_total = 0;
long double tendered_cash = 0;
long long change = 0;
int remainder = 0;
int temp = 0;
long long twenties,tens,fives,ones,quarters,dimes,nickels,pennys;
printf("Welcome to change counter by Jeremy Red\n");
printf("\nPlease enter the total amount of purchase : $");
scanf("%f",&purchase_total);
printf("%d \n",purchase_total);
printf("\nPlease enter the amount tendered : $");
scanf("%f",&tendered_cash);
printf("%d \n",tendered_cash);
change = int((tendered_cash - purchase_total)*100);
printf("Your change is : $%d\n", change);
printf("-------------------------------------------\n");
twenties = change / twenty;
change %= twenty;
tens = change / ten;
change %= ten;
fives = change / five;
change %= five;
ones = change / one;
change %= one;
quarters = change / quarter;
change %= quarter;
dimes = change / dime;
change %= dime;
nickels = change / nickel;
change %= nickel;
pennys = change / penny;
printf("Twenties : %d \n",twenties);
printf("Tens : %d \n",tens);
printf("Fives : %d \n",fives);
printf("Ones : %d \n",ones);
printf("Quarters : %d \n",quarters);
printf("Dimes : %d \n",dimes);
printf("Nickels : %d \n",nickels);
printf("Pennys : %d \n",pennys);
printf("-------------------------------------------\n");
printf("Thank you for using change counter!");
scanf("%f",&tendered_cash);
return 0;
}
|