![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Programmer
Join Date: Dec 2004
Posts: 87
Rep Power: 4
![]() |
How do I make this work? simple problem
Ok, I'm trying to make it so you can put in the number of quarters, dimes, nickels, and pennies in that order, and it shows you how many dollars and how many cents that adds up to.
For example: 3 quarters 2 dimes 1 nickel 6 pennies = $1.06 And the program should output it like this: Dollars: 1 Change: .06 Here's my code so far: #include "stdafx.h" #include <iostream> using namespace std; int main() { cout << "Enter quarters, dimes, nickels, and pennies in that order:\n"; int quarters, dimes, nickels, pennies; cin >> quarters >> dimes >> nickels >> pennies; const double penny = .01; const double nickel = .05; const double dime = .10; const double quarter = .25; double result = (penny * pennies) + (nickel * nickels) + (dime * dimes) + (quarter * quarters); double change = result % 1; double dollars = (int)result; cout << result << " is the total amount" << endl; cout << "Dollars: " << dollars << endl; cout << "Change: " << change << endl << endl << endl; return 0; } How do I make it work. I can't figure out what to do with my dollars and cents, and I tried modulousing them result % 1 but I can't because result is double. Please help, need asap, thanks Jason |
|
|
|
|
|
#2 |
|
The Supreme Ruler
![]() Join Date: May 2004
Location: Houston
Posts: 1,476
Rep Power: 6
![]() |
Well, it would take a little messing around, but it can be done. Printf format specifiers might help.
The way I'd do it would just be to use ints. Have penny as 1, nickel as 5, and so on. When you get the total, the total divided by 100 would be the number of dollars and the total modulus 100 would be cents.
__________________
"Every gun that is made, every warship launched, every rocket signifies, in the final sense, a theft from those who hunger and are not fed, from those who are cold and are not clothed. The world in arms is not spending money alone. It is spending the sweat of its laborers, the genius of its scientists, the hopes of its children." - Dwight D. Eisenhower |
|
|
|
|
|
#3 |
|
Programmer
Join Date: Dec 2004
Posts: 87
Rep Power: 4
![]() |
Woah, I never would have thought of that. Thanks machiavelli
Give me a few moments, and I'll repost my code Jason |
|
|
|
|
|
#4 |
|
Programmer
Join Date: Dec 2004
Posts: 87
Rep Power: 4
![]() |
// asdjkfl;.cpp : Defines the entry point for the console application.
// #include "stdafx.h" #include <iostream> using namespace std; int main() { cout << "Enter quarters, dimes, nickels, and pennies in that order:\n"; int quarters, dimes, nickels, pennies; cin >> quarters >> dimes >> nickels >> pennies; const int penny = 1; const int nickel = 5; const int dime = 10; const int quarter = 25; int result = (penny * pennies) + (nickel * nickels) + (dime * dimes) + (quarter * quarters); int change = result % 100; int dollars = result / 100; cout << result << " is the total amount" << endl; cout << "Dollars: " << dollars << endl; cout << "Change: " << change << endl << endl << endl; return 0; } guess I'm a quick learner ![]() thanks again machiavelli |
|
|
|
|
|
#5 |
|
The Supreme Ruler
![]() Join Date: May 2004
Location: Houston
Posts: 1,476
Rep Power: 6
![]() |
No problem. Glad you got it working.
__________________
"Every gun that is made, every warship launched, every rocket signifies, in the final sense, a theft from those who hunger and are not fed, from those who are cold and are not clothed. The world in arms is not spending money alone. It is spending the sweat of its laborers, the genius of its scientists, the hopes of its children." - Dwight D. Eisenhower |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|