Construct a C program which computes the minimum number of b

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.

Solution

#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\ \", 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\ dimes $%d\ nickels $%d\ pennies $%d\ \",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

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 t
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 t

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site