Telling program not to output value when...

Hi, I am writing a program to output a dollar value in 20's bills, 10's bills, 5's bills, and singles.

So if I had something like $54, it would display 2 x 20's bills, 1 x 10's bills, and 4 x singles bills.

I'm having problems with getting the program to NOT display 0 x 5's bills.

Is there a way to write a while loop which checks to see if any of the values is 0 and if the value is 0, makes sure that IT IS NOT DISPLAYED and only displays the values that are not 0
#include <iostream>
#include <fstream>
#include <cmath>
using namespace std;

void makeChange(double money, int &twenties, int &tens, int &fives, int &singles, int &quarters, int &dimes, int &nickels, int
&pennies){
int y
int z
y = int(money);
twenties = y / 20;
tens = (y % (20*twenties)) / 10;
fives = (y % ((20*twenties) + (10*tens))) / 5;
singles = (y % ((20*twenties) + (10*tens) + (5*fives))) / 1;
z = money - y;
quarters = z / 0.25;
dimes = (z % (0.25*quarters)) / 0.10;
nickels = (z % ((0.25*quarters) + (0.10*dimes))) / 0.05;
pennies = (z % ((0.25*quarters) + (0.10*dimes) + (0.05*nickels))) / 0.01;
return;
}

void printChange(ofstream &ofile, double money, int twenties, int tens, int fives, int singles, int quarters, int dimes, int
nickels, int pennies){
ofile << "The change for" << money << endl;

if (twenties + tens + fives + singles == 0)
ofile << "In notes is:" << "Nothing" << endl;

else if (twenties != 0 && tens != 0 && fives != 0 && singles != 0)
ofile << "In notes is:" << twenties << " x $20 Dollars, " << tens << " x $10 Dollars, " << fives << " x $5 Dollars, " <<
singles << " x $1 Dollars." << endl;

else if (twenties != 0 && tens != 0 && fives != 0 && singles == 0)
ofile << "In notes is:" << twenties << " x $20 Dollars, " << tens << " x $10 Dollars, " << fives << " x $5 Dollars." <<
endl;

else if (twenties != 0 && tens != 0 && fives == 0 && singles == 0)
ofile << "In notes is:" << twenties << " x $20 Dollars, " << tens << " x $10 Dollars." << endl;

else if (twenties != 0 && tens == 0 && fives == 0 && singles == 0)
ofile << "In notes is:" << twenties << " x $20 Dollars." << endl;

else if (twenties == 0 && tens != 0 && fives != 0 && singles != 0)
ofile << "In notes is:" << tens << " x $10 Dollars, " << fives << " x $5 Dollars, " << singles << " x $1 Dollars." << endl;

else if (twenties == 0 && tens == 0 && fives != 0 && singles != 0)
ofile << "In notes is:" << fives << " x $5 Dollars, " << singles << " x $1 Dollars." << endl;

else if (twenties == 0 && tens == 0 && fives == 0 && singles != 0)
ofile << "In notes is:" << singles << " x $1 Dollars." << endl;

else if (twenties == 0 && tens != 0 && fives == 0 && singles == 0)
ofile << "In notes is:" << tens << " x $10 Dollars,." << endl;

else if (twenties == 0 && tens == 0 && fives != 0 && singles == 0)
ofile << "In notes is:" << fives << " x $5 Dollars." << endl;

else if (twenties == 0 && tens != 0 && fives != 0 && singles == 0)
ofile << "In notes is:" << tens << " x $10 Dollars, " << fives << " x $5 Dollars." << endl;

else if (twenties == 0 && tens != 0 && fives == 0 && singles != 0)
ofile << "In notes is:" << tens << " x $10 Dollars, " << singles << " x $1 Dollars." << endl;

else if (twenties != 0 && tens == 0 && fives != 0 && singles == 0)
ofile << "In notes is:" << twenties << " x $20 Dollars, " << fives << " x $5 Dollars." << endl;

else if (twenties != 0 && tens == 0 && fives != 0 && singles != 0)
ofile << "In notes is:" << twenties << " x $20 Dollars, " << fives << " x $5 Dollars, " << singles << " x $1 Dollars." <<
endl;

else if (twenties != 0 && tens != 0 && fives == 0 && singles != 0)
ofile << "In notes is:" << twenties << " x $20 Dollars, " << tens << " x $10 Dollars, " << singles << " x $1 Dollars." <<
endl;
// this is the code I have without the while loop. As you can see, I had to write A LOT of if statements that took into account every possibility. Is there a way to express thin in a smaller while loop?
Topic archived. No new replies allowed.