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:

#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;
}
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!

8 comments:

Xenototh said...

So... is this what is going on in my cash register?

Lt Nite said...

Sounds like a cash register lol.

Miyamoto Karyuu said...

alright C++ sounds actually interesting, i think i might check it out when i have some patience..xD lazy me

Whitelight said...

thanks! for the post!

JustAnotherBloggerNamedCisco said...

i want to know how to exploit this so i can take extra money from poeple when i ring them up Lololol

fit4life said...

fascinating!

baka1236 said...

hahaha, cash register

Anonymous said...

i really like the way you move mmmm

Post a Comment