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

You are trying to get enough change to make a dollar. You want to write a progra

ID: 3792360 • Letter: Y

Question

You are trying to get enough change to make a dollar. You want to write a program that counts the amount of change you have and tells you how far you are away from a dollar.

#include <iostream>
using namespace std;

int main() {

const double pennies = 0.01, nickels = 0.05, dimes = 0.10, quarters = 0.25;
double dollar = 1.0;
double total;

cout << "Input how many pennies, nickels, dimes, and quarters do you have?" << endl;

/* Type your code here. */

cout << "You are " <<<< " cents short of a dollar " ;

return 0;
}

Explanation / Answer

#include <iostream>
#include <math.h>
#include <cmath>  
using namespace std;

int main() {

const double pennies = 0.01, nickels = 0.05, dimes = 0.10, quarters = 0.25;
double dollar = 1.0;
double total;
int p_count,n_count,d_count,q_count;

cout << "Input how many pennies, nickels, dimes, and quarters do you have?" << endl;

cin>> p_count;
cin>> n_count;
cin>> d_count;
cin>> q_count;

total = (p_count*pennies) + (n_count * nickels) + (d_count *dimes) + (q_count *quarters);

cout << "you have amonut of change " << total << endl ;

if (total < 1.0)
{
   cout << "You are " << abs(remainder(total,dollar)) << " cents short of a dollar " << endl;
}
else
{
cout << "You are " << dollar - (remainder(total,dollar)) << " cents short of a dollar " ;

}


   return 0;    
}

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