The world’s Largest Sharp Brain Virtual Experts Marketplace Just a click Away
Levels Tought:
Elementary,Middle School,High School,College,University,PHD
| Teaching Since: | Apr 2017 |
| Last Sign in: | 103 Weeks Ago, 2 Days Ago |
| Questions Answered: | 4870 |
| Tutorials Posted: | 4863 |
MBA IT, Mater in Science and Technology
Devry
Jul-1996 - Jul-2000
Professor
Devry University
Mar-2010 - Oct-2016
Question: 1. Modify (dollar.c) (Write a C program that asks ...
1. Modify (dollar.c) (Write a C program that asks the user to enter a U.S. dollar amountand then shows how to pay that amount using the smallest number of $20, $10, $5, and $1
bills.) So it includes the following function:
void pay_amount(int dollars, int *twenties, int *tens, int*fives, int *ones);
The function determines the smallest number of $20, $10, $5, and $1 bills necessary to paythe amount represented by the dollars parameter. The twenties parameter points toa variable in which the function will store the number of $20 bills required. The tens,fives, and ones parameters are similar. Modify the main function so it callspay_amount.
This is dollar.c:
#include <stdio.h>
int main(){
//initialize variables and read inputint dollar = 0, twenty = 0, ten = 0, five = 0, one =0;
printf("Enter a dollar amount:n");
scanf("%d", &dollar);
//check the range of the input amountif(dollar < 0 || dollar > 1000000000)Â Â Â
printf("Invalid amount %d,nAmount must be between 0 and 1000000000,
inclusiven", dollar);Â Â Â Â Â Â Â Â
else {
twenty = dollar/20;
ten = (dollar - (twenty * 20))/10;
five = (dollar - (twenty * 20) - (ten * 10))/5;
one = dollar - (twenty * 20) - (ten * 10) - (five * 5);
printf("$20 bills: %dn", twenty);
printf("$10 bills: %dn", ten);Â Â Â Â Â Â Â Â
printf("$5 bills: %dn", five);Â Â Â Â Â Â Â Â
printf("$1 bills: %dn", one);
}
return 0;
}
-----------