As the name implies, this program works by having the user input a number, then the change that could be made out for that number (in dollars) is outputted. Compile in an IDE to test it out for yourself!#include <iostream>#include <string>using namespace std;
int main(){int total, dollars, quarters, dimes, nickels, leftover;cout << "Enter number of pennies to make change for: ";cin >> total;dollars = total / 100;leftover = total % 100;quarters = leftover / 25;leftover %= 25;dimes = leftover / 10;leftover %= 10;nickels = leftover / 10;leftover %= 5;cout << "Dollars: " << dollars << endl;cout << "Quarters: " << quarters << endl;cout << "Dimes: " << dimes << endl;cout << "Nickels: " << nickels << endl;cout << "Pennies: " << leftover << endl;system("pause");return 0;}
Adventures in Game Development -- Day 10
While working through C++ Demystified, I found a cool little code example called "The Change Machine". Here is the code:
Subscribe to:
Post Comments (Atom)
8 comments:
So... is this what is going on in my cash register?
Sounds like a cash register lol.
alright C++ sounds actually interesting, i think i might check it out when i have some patience..xD lazy me
thanks! for the post!
i want to know how to exploit this so i can take extra money from poeple when i ring them up Lololol
fascinating!
hahaha, cash register
i really like the way you move mmmm
Post a Comment