Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

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;
}

EAC nal project Debuglfinal project.exe Total Amount Due $101 Total Amount Paid: $150 Total Change Due $48.73 Number of twenty dollar bills due 2 Number of ten dollar bills due: 0 Number of five dollar bills due Number of one dollar bills due Number of quarters due 2 Number of dimes due 2 Number of nickels due Number of pennies due 3 El

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

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote