Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
ChangeCalculator Program C++
#include <iostream>
#include <math.h>
using namespace std;
int main() {
//reads from input file, or takes user input. 1st is your total amount, and the second is how much you paid
double total;
//get change
cin >>total;
double paid;
cin >> paid;
double change = paid - total;
if(paid > total)
{
int quarters = change/.25;
int dimes = (change - .25*quarters)/.10;
int nickels = (change - .25*quarters - .10*dimes)/.05;
int pennies = (change - .25*quarters - .10*dimes - .05*nickels)/.01;
cout <<"Q: " << quarters << endl;
cout <<"D: " << dimes <<endl;
cout <<"N: " << nickels <<endl;
cout <<"P: " << pennies << endl;
}
else
cout << "You can't pay less than the total, now you owe money.";
}
}
@Sajgon66

This comment has been minimized.

Copy link

commented Jul 9, 2017

Program has a problem with input 0.03 total and 0.01 cost for instance.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.