How can I modify this code so that it doesn\'t show variable values for 0\'s. Fo
ID: 3575184 • Letter: H
Question
How can I modify this code so that it doesn't show variable values for 0's. For example, Amount due is $101.27, amount paid is $150. Change is $48.73. Currently my output for this data would look like this:
How can I modify the following code so that when a value comes up 0 (like in this instance with ten dollar bills and nickles) they won't show in the output?
#include "stdafx.h"
#include <iostream>
#include <string>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <iomanip>
using namespace std;
// Declare variables
double amtdue, amtpaid, difference;
int change, dollars20, dollars10, dollars5, dollars1;
int quarter, nickel, dime, penny;
int main()
{
// Input
cout << "Total Amount Due: $";
cin >> amtdue; cout << endl;
cout << "Total Amount Paid: $";
cin >> amtpaid; cout << endl;
if (amtpaid > amtdue)
{
// The amount difference calculate new variables.
difference = amtpaid - amtdue;
difference = difference + 0.00001;
cout << fixed << setprecision(2) << "Total Change Due: $" << difference << endl << endl;
difference = difference * 100;
change = (int)(difference);
//calculation of money that is due
dollars20 = change / 2000;
change = change % 2000;
dollars10 = change / 1000;
change = change % 1000;
dollars5 = change / 500;
change = change % 500;
dollars1 = change / 100;
change = change % 100;
quarter = change / 25;
change = change % 25;
dime = change / 10;
change = change % 10;
nickel = change / 5;
change = change % 5;
penny = change / 1;
change = change % 1;
// Output
cout << "Number of twenty dollar bills due: " << dollars20 << endl;
cout << "Number of ten dollar bills due: " << dollars10 << endl;
cout << "Number of five dollar bills due: " << dollars5 << endl;
cout << "Number of one dollar bills due: " << dollars1 << endl;
cout << "Number of quarters due: " << quarter << endl;
cout << "Number of dimes due: " << dime << endl;
cout << "Number of nickels due: " << nickel << endl;
cout << "Number of pennies due: " << penny << endl;
}
else {
cout << "No change is due." << endl;
}
cin.ignore(100);
return 0;
}
Explanation / Answer
if anything is specified in stdfax.h, then anything can be solved. of that. or if any code exists for the header file, then use if condition, this can be solved
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.