Gucci
2013-01-15 00:12:02
So my prof said this would be a good question to figure out:
Came up with a method that basically continue ^that until pennies and then start for if (A >= 100) until pennies and repeat for quarters-pennies, dimes-pennies, nickels-pennies. Just a bunch of if..else statements there must be a easier way to do it. Please suggest/show examples
@Brandon
@Daniel
Write a program that will prompt the user for an integer number of cents and will determine the number of toonies, loonies, quarters, dimes, nickels and pennies that are required for this amount of change. The program will display the results to the screen in a pleasing manner.
Examples:
Input: 150
Output: 1 loonie, 2 quarters
Input: 430
Output: 2 toonies, 1 quarter, 1 nickel
#include <cstdlib>
#include <iostream>
using namespace std;
void www()
{
}
int main()
{
double A, B, C, D, E, F, G, J, K, M, N;
short int H, L, P;
cout << "Input the number of cents.\n";
cin >> A;
if ( A >= 200) {
B = (A/200);
H = (A/200);
J = ((B - H)*200);
if ( J >= 100) {
K = (J/100);
L = (J/100);
M = ((K - L)*100);
if ( M >= 25) {
D = (M/25);
P = (M/25);
N = ((D - P)*25);
}
}
else if ( J < 100 ) {
D = (J/25);
P = (J/25);
N = ((D - P)*25);
}
}
cout << "Toonies: " << H << " Loonies: " << L << " Quarters: " << P << " Dimes: " << E << " Nickels: " << F << " Pennies: " << G << endl;
system("PAUSE");
return 0;
}Came up with a method that basically continue ^that until pennies and then start for if (A >= 100) until pennies and repeat for quarters-pennies, dimes-pennies, nickels-pennies. Just a bunch of if..else statements there must be a easier way to do it. Please suggest/show examples
@Brandon
@Daniel