Skip to content

Instantly share code, notes, and snippets.

@rlingineni
Created September 20, 2015 18:14
Show Gist options
  • Save rlingineni/93b57d67e37134735df5 to your computer and use it in GitHub Desktop.
Save rlingineni/93b57d67e37134735df5 to your computer and use it in GitHub Desktop.
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
Copy link

Sajgon66 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