Created
September 20, 2015 18:14
-
-
Save rlingineni/93b57d67e37134735df5 to your computer and use it in GitHub Desktop.
ChangeCalculator Program C++
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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."; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Program has a problem with input 0.03 total and 0.01 cost for instance.