Below is the code I have, and the output is below that. It all seems right, but I don't want it to print out the 0's if they appear in the output. How do I do that?
#include <iostream>
#include <iomanip>
using namespace std;
int main() {
double moneyOwed = 0.0;
double moneyPaid = 0.0;
double change = 0.0;
int change1 = 0;
int dollars = 0;
int quarters = 0;
int dimes = 0;
int nickels = 0;
int pennies = 0;
cout << "Customer owes: $";
cin >> moneyOwed;
cout << "Customer pays: $";
cin >> moneyPaid;
cout << fixed << setprecision(2);
//calculations
change = moneyPaid - moneyOwed;
change1 = change * 100;
dollars = change1 / 100;
quarters = change1 % 100 / 25;
dimes = change1 % 100 % 25 / 10;
nickels = change1 % 100 % 25 % 10 / 5;
pennies = change1 % 100 % 25 % 10 % 5;
//change
cout << "Change due: $" << change << endl;
cout << "Dollars: " << dollars << endl;
cout << "Quarters: " << quarters << endl;
cout << "Dimes: " << dimes << endl;
cout << "Nickles: " << nickels << endl;
cout << "Pennies: " << pennies << endl;
cin >> change;
return 0;
}
Customer owes: $1.30
Customer owes: $2.00
Change due: $0.70
Dollars: 0
Quarters: 2
Dimes: 2
Nickles: 0
Pennies: 0