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...
Lab 2 Write a C program that runs on ocelot for a mini calculator using only...
Lab 2 Write a C program that runs on ocelot for a mini calculator using only the command line options. You must use getopt to parse the command line. The calculator will only do addition, subtraction, multiplication, division, and a power of 2. Usage: minicalc [-a num] [-d num] [-m num] [-s num] [-x] value • The variable value is the starting value. • Value should be validated to be an integer between 1 and 50 inclusive. Error message and...
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...
I did already posted this question before, I did get the answer but i am not...
I did already posted this question before, I did get the answer but i am not satisfied with the answer i did the code as a solution not the description as my solution, so i am reposting this question again. Please send me the code as my solution not the description In this project, build a simple Unix shell. The shell is the heart of the command-line interface, and thus is central to the Unix/C programming environment. Mastering use of...
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...
Discuss how the respective organizations’ relations with stakeholders could have potentially been affected by the events...
Discuss how the respective organizations’ relations with stakeholders could have potentially been affected by the events that took place at Enron and how the situation could have been dealt with differently to prevent further damage? 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,...