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 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118
|
// Written By Tim Zumsteg
// Project 05- Chapter 5
// Due March 1, 2013
// C++ for Engineers
#include <iostream>
#include <cmath>
using namespace std;
void make_change(int&, int&, int&, int&, int&, int&, int&, int&, int&);
void print_change( int&, int&, int&, int&, int&, int&, int&, int&);/// new function
int twenties=2000, tens=1000, fives=500, ones=100, new_twenties, new_tens, new_fives, new_ones, new_quarters, new_dimes, new_nickels, new_pennies;
int quarters=25, dimes=10, nickels=5, pennies=1, add_twenties, add_tens, add_fives, add_ones, add_quarters, add_dimes, add_nickels, add_pennies;
int total, initial_change;
char command;
int main()
{
//void make_change(int&, int&, int&, int&, int&, int&, int&, int&, int&); //// already declared your function above
//int twenties, tens, fives, ones, quarters, dimes, nickels, pennies; ////use the global variables above
cout<< "\n\n\nWelcome to our store! Please enter the initial amount of change your customer has given you in pennies. ";
cout<< "For example $58.67 would be entered in as 5867.\n";
cin>> initial_change;
cout<< "You have entered in a total of " <<initial_change <<".\n";
cout<< "You need to give the customer the following change:\n\n";
make_change (initial_change, twenties, tens, fives, ones, quarters, dimes, nickels, pennies);
print_change(twenties, tens, fives, ones, quarters, dimes, nickels, pennies); //// new function
cout<< "\n\n|--------------MENU--------------|\n";
cout<< "| [1] Add Twenties |\n";
cout<< "| [2] Add Tens |\n";
cout<< "| [3] Add Fives |\n";
cout<< "| [4] Add Ones |\n";
cout<< "| [5] Add Quarters |\n";
cout<< "| [6] Add Dimes |\n";
cout<< "| [7] Add Nickels |\n";
cout<< "| [8] Add Pennies |\n";
cout<< "| [9] Refigure Change |\n";
cout<< "| [0] Exit Program |\n";
cout<< "|--------------------------------|\n";
cout<< "\nPlease enter the command you would like to do next. You can add money";
cout<< " or change the amount your customer has given you. You can even exit the program.\n";
cin>> command;
switch (command)
{
//void make_change (int&, int&, int&, int&, int&, int&, int&, int&, int&); //// function already declared above
//int add_twenties, add_tens, add_fives, add_ones, add_quarters, add_dimes, add_nickels, add_pennies; //// will use the global variables
//int new_twenties, new_tens, new_fives, new_ones, new_quarters, new_dimes, new_nickels, new_pennies; //// will use the global variables
case '1':
cout<< "\n\nEnter amount of twenties you'd like to add.\n";
cin>> add_twenties;
cout<< "You now need to give the customer the current change:\n";
new_twenties= twenties+add_twenties;
//make_change (initial_change, new_twenties, tens, fives, ones, quarters, dimes, nickels, pennies); //// don't need to recalculate since global variables
print_change(new_twenties, tens, fives, ones, quarters, dimes, nickels, pennies); //// new function. note use new_twenties
break;
....
case '9':
int new_change;
cout<< "Please enter the amount of change your customer has given you\n";
cin>> new_change;
cout<< "You need to give the customer the current change of:\n\n";
make_change (new_change, twenties, tens, fives, ones, quarters, dimes, nickels, pennies); //// do need to recalculate change
print_change(twenties, tens, fives, ones, quarters, dimes, nickels, pennies); /// new function
break;
case 0:
break;
}
return 0;
}
void make_change (int& initial_change, int& twenties, int& tens, int& fives, int& ones,
int& quarters, int& dimes, int& nickels, int& pennies)
{
twenties= (initial_change/2000);
tens= (initial_change-(twenties*2000))/1000;
fives= (initial_change-(twenties*2000)-(tens*1000))/500;
ones= (initial_change-(twenties*2000)-(tens*1000)-(fives*500))/100;
quarters= (initial_change-(twenties*2000)-(tens*1000)-(fives*500)-(ones*100))/25;
dimes= (initial_change-(twenties*2000)-(tens*1000)-(fives*500)-(ones*100)-(quarters*25))/10;
nickels= (initial_change-(twenties*2000)-(tens*1000)-(fives*500)-(ones*100)-(quarters*25)-(dimes*10))/5;
pennies= (initial_change-(twenties*2000)-(tens*1000)-(fives*500)-(ones*100)-(quarters*25)-(dimes*10)-(nickels*5))/1;
}
void print_change(int& twenties, int& tens, int& fives, int& ones,
int& quarters, int& dimes, int& nickels, int& pennies)
{
cout<< "Twenties: " << twenties << "\n";
cout<< "Tens: " << tens << "\n";
cout<< "Fives: " << fives << "\n";
cout<< "Ones: " << ones << "\n";
cout<< "\n\nQuarters: " << quarters << "\n";
cout<< "Dimes: " << dimes << "\n";
cout<< "Nickels: " << nickels << "\n";
cout<< "Pennies: " << pennies << "\n";
}
|