Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Make Change program - C++ **Please read all, this is the fourth time i\'ve poste

ID: 668360 • Letter: M

Question

Make Change program - C++
**Please read all, this is the fourth time i've posted this, and have gotten incorrect answers the previous times**
**Needs to be in C++, NOT any other language!**

Write a program to input two float values. The first float is the cost of some purchase made, or the cost of goods, and the second is the payment value towards the cost. You are to determine the change (if any) to return to the customer. You must also determine if they gave you enough money to cover the cost, if they didn't, print out you are short on funds, so pay more.
The change should be the number of 20 dollar bills to return, then the number of 10's, 5's, and 1's in bills. Then the change for coins, the number of 50 cents, .25 cents (quarters), 10 cents (dimes), 5 cents (nickels), and pennies. **DO NOT print out 0 for any of the above values (if they don't get any 20 dollar bills back, don't print "0 20 dollar bills". You just don't print anything.)**
Print out the 'cost' and the 'payment' and then the amount of change to return.
**NOTE: Can't use arrays, classes, getch(), length, size, as we haven't covered them.**

Example:

0.81     1.00
Example output:
purchase   pay   change
0.81          1.00    1 dime, 1 nickel, 4 pennies

Explanation / Answer

#include <iostream>

using namespace std;

int main()

{

float cost,

payment;

int amountLeft;

int change,

dollar,

quarters,

dimes,

nickels,

pennies;

cout << "Please enter the cost: ";

cin >> cost;

cout << "Enter how much you paid: ";

cin >> payment;

if (payment < cost)

cout << "Not enough money!";

payment = payment * 100 + 0.5;

cost = cost * 100;

amountLeft = payment - cost;

dollar = amountLeft / 100;

change = amountLeft % 100;

quarters = change / 25;

change = change % 25;

dimes = change / 10;

change = change % 10;

nickels = change / 5;

change = change % 5;

pennies = change;

cout << "You have " << dollar << " dollars, " << quarters << " quarters, " << dimes << " dimes, " << nickels << " nickels, " << pennies << " pennies left."<< endl;

return 0;

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote