Question

Construct a C program which computes the minimum number of bills and coins needed to make...

Construct a C program which computes the minimum number of bills and coins needed to make change for a particular purchase. The cost of the item is $21.17 and the amount tendered is $100.00. These values should be built into your program using assignment statements rather than input into the program during program runtime. Your program should indicate how many bills and coins of each denomintaion are needed for the change. You should make use of the following denominations: Bills: twenty, ten, five, one Coins: quarter, dime, nickel, penny YOur program should make use of integer division as well asthe modulus operator. Do not use the subtraction operator in place of the modulus operator. What I am REALLY looking for is an explanation of which formulas I should be using and how I am supposed to implement the modulus operator within the formula.

Homework Answers

Answer #1

#include <stdio.h>

int main()
{
double cost, total, change;
int cents,quarters, dimes,nickels,penny;
printf("Enter The cost of the item: ");
scanf("%lf", &cost);
printf("Enter the amount tendered: ");
scanf("%lf", &total);
change = total - cost;
  
cents = (int)change;
printf("%d\n", cents);
  
quarters = cents / 25;// it gives the number of quarters
           cents = cents % 25; //it gives the remaining change after calculating quarters. % modular will give you the remainder
           dimes = cents/ 10;// it gives the number of dimes
           cents = cents % 10;//it gives the remaining change after calculating dimes. % modular will give you the remainder
           nickels = cents / 5;// it gives the number of nickels
           cents = cents % 5;//it gives the remaining change after calculating nickels . % modular will give you the remainder
           penny = cents;// it gives the number of pennys
             

   printf("quarters $%d\ndimes $%d\nnickels $%d\npennies $%d\n",quarters, dimes, nickels, penny );
return 0;
}

Output:

sh-4.2$ gcc -o main *.c                                                                                                                                                                                                                                                

sh-4.2$ main                                                                                                                                                                                                                                                           

Enter The cost of the item: 21.17                                                                                                                                                                                                                                      

Enter the amount tendered: 100                                                                                                                                                                                                                                         

78                                                                                                                                                                                                                                                                     

quarters $3                                                                                                                                                                                                                                                            

dimes $0                                                                                                                                                                                                                                                               

nickels $0                                                                                                                                                                                                                                                             

pennies $3

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
C++ PROGRAMMING Hi! I have to make a program that adds fractions and simplifies them. I...
C++ PROGRAMMING Hi! I have to make a program that adds fractions and simplifies them. I feel like I know how to write that. What I'm having trouble with is implementing two files the professer gave us. I would appreicate any help in understanding their purpose as in if Im supposed to take information from those files or give it information. Thank you! I have attatched the homework instructions and the two files given. Implementation The main program, called calculator.cpp...
I am trying to make a program in C# and was wondering how it could be...
I am trying to make a program in C# and was wondering how it could be done based on the given instructions. Here is the code that i have so far... namespace Conversions { partial class Form1 { /// <summary> /// Required designer variable. /// </summary> private System.ComponentModel.IContainer components = null; /// <summary> /// Clean up any resources being used. /// </summary> /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param> protected override void Dispose(bool disposing) { if...
Discuss ethical issues that can be identified in this case and the mode of managing ethics...
Discuss ethical issues that can be identified in this case and the mode of managing ethics Enron finds itself in this case. How would you describe the ethical culture and levels of trust at Enron? Provide reasons for your assessment. THE FALL OF ENRON: A STAKEHOLDER FAILURE Once upon a time, there was a gleaming headquarters office tower in Houston, with a giant tilted "£"' in front, slowly revolving in the Texas sun. The Enron Corporation, which once ranked among...
What role could the governance of ethics have played if it had been in existence in...
What role could the governance of ethics have played if it had been in existence in the organization? Assess the leadership of Enron from an ethical perspective. THE FALL OF ENRON: A STAKEHOLDER FAILURE Once upon a time, there was a gleaming headquarters office tower in Houston, with a giant tilted "£"' in front, slowly revolving in the Texas sun. The Enron Corporation, which once ranked among the top Fortune 500 companies, collapsed in 2001 under a mountain of debt...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT