C++ cashier code -
the question:
giving change. implement program directs cashier how give change. program has 2 inputs: amount due , amount received customer. display dollars, quarters, dimes, nickels, , pennies customer should receive in return.
what have far:
#include <iostream> using namespace std; int main() { double amount_due; double amount_recieved; cout << "enter amount due: " << endl; cin >> amount_due; cout << "enter amount received: "; cin >> amount_recieved; int change = amount_recieved - amount_due; int dollar = 100; int quarters = 25; int dimes = 10; int nickels = 5; int pennies = 1; //return change in full dollars cout << "dollars: " << change % 100 << endl; //return change in quarters cout << "quarters: " << (change % 100) % 25 << endl; //return change in dimes cout << "dimes: " << ((change % 100) % 25) % 10 << endl; // return change in nickels cout << "nickels: " << (((change % 100) % 25) % 10) % 5 << endl; //return change in pennies cout << "pennies: " << ((((change % 100) % 25) % 10) % 5) % 1 << endl; system("pause"); return 0; }
i realize there other 1 of these answered may advanced use in code, doing wrong?
what want same cashier do.
first ensure change represented whole pennies.
then provide enough dollars until change remaining less dollar. move on quarters, dimes, nickels , pennies.
so dollar case, pseudo-code be:
dollars = change / 100 # integral number of dollars change = change % 100 # , reduce change-left-to-go accordingly print dollars, " dollars"
it should simple matter apply logic other coin types in order of reducing value.
Comments
Post a Comment