/****************************************** * * This program demonstrates the use of modulus and * division function, and the general programming style. * * Author: Xiannong Meng * Date: June 7, 2001 * ******************************************/ #include using namespace std; const double SALES_TAX_RATE = 0.0875; // 8.75% sales tax void main(void) { int amountPaid, // amount paid to the seller itemCost, // how much it costs amount2Return, // 'change' to the customer quarters2Return, dimes2Return, // number of dimes to return nickles2Return, // number of nickles to return pennies2Return, // number of pennies to rerun totalCost; // final cost = item cost + tax cout << " Specify the cost (in cents e.g. 536 means 5 dollars 36 cents) : "; cin >> itemCost; cout << " Specify amount paid (in cents) : "; cin >> amountPaid; /* calculate the total cost in cents */ totalCost = int((itemCost * (1 + SALES_TAX_RATE)) + 0.5); /* calculate the change */ amount2Return = amountPaid - totalCost; /* print a message to the user */ cout << " Total cost (sales tax incl.) : " << totalCost << endl; cout << " Amount remitted : " << amountPaid << endl; cout << " Amount to return : " << amount2Return << endl; /* out of the amount to return, calculate how many quarters */ quarters2Return = amount2Return / 25; amount2Return = amount2Return % 25; /* how many dimes? */ dimes2Return = amount2Return / 10; amount2Return = amount2Return % 10; /* how many nickles? */ nickles2Return = amount2Return / 5; amount2Return = amount2Return % 5; /* finally how many pennies */ pennies2Return = amount2Return; /* print out the results */ cout << " Quarters returned : " << quarters2Return << endl; cout << " Dimes returned : " << dimes2Return << endl; cout << " Nickles returned : " << nickles2Return << endl; cout << " Pennies returned : " << pennies2Return << endl; }