Stuck on Homework assignment (Converting pennies into least amount of coinage.)
Feb 3, 2017 at 12:02am UTC
Hello so currently I am to the point where my program shows the amount of dollars and quarters that are in the bag of pennies. It calculates the amount of pennies after the dollars and quarters. I can't get the amount of dimes to come out correctly.
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
#include <iostream>
#include <string>
#include <iomanip>
using namespace std;
int main() {
//PART 1
//Sets variables for amount of coins and dollars.
string usersName;
int amountofDollars;
int amountofQuarters;
int amountofDimes;
int amountofNickels;
int amountofPennies;
//Sets variables for value of coins and dollars.
float dollarValue = 1.00;
float quarterValue = 0.25;
float dimeValue = 0.10;
float nickelValue = 0.05;
float penniesValue = 0.01;
//Get amount of coins and dollars.
cout << "Enter account owners name: " ;
getline (cin, usersName);
cout << "Enter number of dollars: " ;
cin >> amountofDollars;
cout << "Enter number of quarters: " ;
cin >> amountofQuarters;
cout << "Enter number of dimes: " ;
cin >> amountofDimes;
cout << "Enter number of nickels: " ;
cin >> amountofNickels;
cout << "Enter number of pennies: " ;
cin >> amountofPennies;
cout << "Account Name: " << usersName << endl;
//Calculations for total.
float totalValueofDollars = amountofDollars * dollarValue;
float totalValueofQuarters = amountofQuarters * quarterValue;
float totalValueofDimes = amountofDimes * dimeValue;
float totalValueofNickels = amountofNickels * nickelValue;
float totalValueofPennies = amountofPennies * penniesValue;
float totalValue = totalValueofDollars + totalValueofQuarters + totalValueofDimes + totalValueofNickels + totalValueofPennies;
cout << fixed << setprecision(2);
cout << "Total Deposit: $" << totalValue << endl << endl;
//PART 2
//Displays bag of Pennies converted into least amount of coinage.
cout << "Bag of Pennies" << endl;
cout << "How many pennies are in the bag of pennies? " ;
cin >> amountofPennies;
cout << "Amount Due:" << endl;
//Converts into least amount of coinage.
int dollarConversion = amountofPennies / 100;
int numberofDollars = dollarConversion % 100;
int remainderpenniesafterdollar = amountofPennies % 100;
int quarterConversion = remainderpenniesafterdollar / 25;
int remainderpenniesafterquarter = amountofPennies % 25;
int dimeConversion = remainderpenniesafterquarter / 25;
cout << "Dollars: " << numberofDollars << endl;
cout << "Number of Pennies left: " << remainderpenniesafterdollar << endl;
cout << "Number of Quarters: " << quarterConversion << endl;
cout << "Number of Dimes: " << dimeConversion << endl;
system("PAUSE" );
return 0;
}
Feb 3, 2017 at 12:20am UTC
So tell us how you have made the calculation by showing us a small program where you can test the method you have rather than wading through and running 78 lines of code. In other words isolate the area and then put that back into the main program.
Topic archived. No new replies allowed.