Question

C Program that prompts the user to enter a number that represents a pile of pennies....

C Program that prompts the user to enter a number that represents a pile of pennies. Then, the program should use that input value to distribute the cents over monetary denominations of dollars, half dollars, quarters, dimes, nickels and pennies. Distribute the pennies over the other denominations with Change function :

   prototype: void Change(int *dollars, int *halfDollars, int *quarters, int *dimes, int *nickels, int *pennies);

The function takes a logical input value via its pennies parameter that represents the total number of pennies to convert. It then calculates a breakdown of dollars and assorted coins to represent the amount in appropriate denominations. Notice that the parameters are all pointer parameters; that's so the function will be able to store the final results in the caller's arguments. After the function has done its work and returned to the caller, the caller can then display the dollars and coins needed to represent the amount.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Answer:

as per you requirement here is the c code:

Raw code:

#include<stdio.h> //including standard input output headerfile

void Change(int *dollars, int *halfDollars, int *quarters, int *dimes, int *nickels, int *pennies);//function declaration

int main(){//main

int dollars=0,halfDollars=0,quarters=0,dimes=0,nickels=0,pennies;//intial values to be passed

printf("Please enter the Pennies:");//asking the pennies

scanf("%d",&pennies);//user input

Change(&dollars, &halfDollars, &quarters, &dimes, &nickels, &pennies);//calling the function

printf("\nDollars: %d \nHalfDollars %d\nQuarters: %d\nDimes: %d\nNickels: %d\nPennies: %d\n",dollars,halfDollars,quarters,dimes,nickels,pennies);//ouput

}

void Change(int *dollars, int *halfDollars, int *quarters, int *dimes, int *nickels, int *pennies){//change function call by reference

*dollars= (*pennies)/100;//to calculate dollars

*pennies= (*pennies)%100;//updating pennies

*halfDollars=(*pennies)/50;//calculate half dollars

*pennies=(*pennies)%50;//updating pennies

*quarters=(*pennies)/25;//calculate quarters

*pennies=(*pennies)%25;//updating pennies

*dimes=(*pennies)/10;//calcualte dimes

*pennies=(*pennies)%10;//updating pennies

*nickels=(*pennies)/5;//calculate nickels

*pennies=(*pennies)%5;//final pennies

}

Code in the editor:

output:

Please follow the indentation as in screenshot of the editor.

If you still have any doubts or queries comment in the comment section.I will get back to you ASAP. Thank you!

Add a comment
Know the answer?
Add Answer to:
C Program that prompts the user to enter a number that represents a pile of pennies....
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. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • it c++ coding. please write on atom software. 1. Write a program that converts dollars into coins a. Request a dolla...

    it c++ coding. please write on atom software. 1. Write a program that converts dollars into coins a. Request a dollar amount as an integer: $5.34 is input as 534 b. Use a constant variable to represent each coin as a fixed value: const int NICKEL 5; c. Use division and the mod function to calculate the number of each coin. Change Calculator Enter dollar amount (as an integer): $534 The equivalent in coins: 21 Quarters 0 Dimes 1 Nickels...

  • Write a program called "ConvertPennies" to input an integer value representing a number of pennies and...

    Write a program called "ConvertPennies" to input an integer value representing a number of pennies and convert it to its equivalent number of Dollars, Quarters, Dimes, Nickels and Pennies. Following is the result of the execution of this program for 292 pennies. Enter the amount of pennies to convert: 292 pennies is equal to 2 one dollar bills 3 quarters 1 dimes 1 nickels 2 pennies Have a nice day! This is given: //********************************************************************** // Programmer: Your first and last...

  • (In Python 3) Write a program with total change amount as an integer input, and output...

    (In Python 3) Write a program with total change amount as an integer input, and output the change using the fewest coins, one coin type per line. The coin types are Dollars, Quarters, Dimes, Nickels, and Pennies. Use singular and plural coin names as appropriate, like 1 Penny vs. 2 Pennies. Ex: If the input is: 0 (or less than 0), the output is: No change Ex: If the input is: 45 the output is: 1 Quarter 2 Dimes So...

  • Write a C program that calculates exact change. In order to receive full credit, please remember...

    Write a C program that calculates exact change. In order to receive full credit, please remember that only int arithmetic is exact, so you’ll need to break up your double into two ints, the one before the decimal point and the one after the decimal point. Another point worth mentioning is that the % operator gives the remainder. In other words, when working with int values, 9 / 5 = 1 whereas 9 % 5 = 4. Keep this in...

  • Write a program called CountCoins.java that prompts the user for the input file name (you can...

    Write a program called CountCoins.java that prompts the user for the input file name (you can copy the getInputScanner() method given in the ProcessFile assignment) then reads the file. The file contains a series of pairs of tokens, where each pair begins with an integer and is followed by the type of coin, which will be “pennies” (1 cent each), “nickels” (5 cents each), “dimes” (10 cents each), or “quarters” (25 cents each), case-insensitively. Add up the cash values of...

  • write a PHP program makes change for a given number of cents. The program should ask...

    write a PHP program makes change for a given number of cents. The program should ask the user for the amount of cents and then output the change for specific denominations of ten dollar bills, five dollar bills, one dollar bills, quarters, dimes, nickels, and pennies. Here is a sample program output for an input of 265 cents: Change for 2 dollars and 65 cents : 0 ten dollar bills 0 five dollar bills 2 one dollar bills 2 quarters...

  • Problem: Implement (in C) the dynamic program algorithm for the coin-change algorithm, discussed in class. Assume...

    Problem: Implement (in C) the dynamic program algorithm for the coin-change algorithm, discussed in class. Assume that the coins with which you make change are quarters, dimes, nickels and pennies. Thus you are going to set n = 4 in your program. The amount k for which you have to make change will be provided by the user and your program will return the minimum number of coins needed and also the break-up of the change in terms of the...

  • Your program must meet the following specifications: 1. At program start, assume a stock of 10 nickels, 10 dimes, 10...

    Your program must meet the following specifications: 1. At program start, assume a stock of 10 nickels, 10 dimes, 10 quarters, and 10 pennies. 2. Repeatedly prompt the user for a price in the form xX.xx, where X denotes a digit, or to enter q' to quit 3. When a price is entered a. If the price entered is negative, print an error message and start over requesting either a new price or to quit (indicated by entering a 'q)...

  • Write a program with total change amount as an integer input, and output the change using...

    Write a program with total change amount as an integer input, and output the change using the fewest coins, one coin type per line. The coin types are Dollars, Quarters, Dimes, Nickels, and Pennies. Use singular and plural coin names as appropriate, like 1 Penny vs. 2 Pennies. Ex: If the input is: 0 the output is: No change Ex: If the input is: 45 the output is: 1 Quarter 2 Dimes

  • I made this C program to count change and make a slip saying the exact dollar...

    I made this C program to count change and make a slip saying the exact dollar and change amount given. every time I run the program it says the change given is 477256577 and i'm not sure what I have done wrong? #include<stdio.h> int main(void) { char first, last; int pennies; int nickels; int dimes; int quarters; int loonies; int change; int t_dollars; int t_cents; printf("Type in your 2 initials and press return> "); scanf("%c%c",&first,&last); printf("%c%c please enter in your...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT