Question

Create a function called totalCoins that takes an integer price of a product (in pennies) and...

Create a function called totalCoins that takes an integer price of a product (in pennies) and an integer amount of money paid (in pennies). It should return via output parameters the number of dollars, quarters, dimes, nickels, and pennies given as change. Must use pointers. C programming

Homework Answers

Answer #1

C Code:

#include<stdio.h>

//definition for totalCoins()
void totalCoins(int price, int amount)
{
    //variables declaration
    int change , dollors , quarters , dimes , nickels , pennies;

    //change is the amount to be returned as change
    change = amount - price;

    dollors=change/100; //calculating dollors from change
    //if dollor is valid or more than 0 than update remaining change value
    if(dollors>=1)
        change=change-dollors*100;

    quarters=change/25;  //calculating quarters from change
    //if quarters is valid or more than 0 than update remaining change value
    if(quarters>=1)
        change=change-quarters*25;

    dimes=change/10;  //calculating dimes from change
    //if dimes is valid or more than 0 than update remaining change value
    if(dimes>=1)
        change=change-dimes*10;

    nickels=change/5;  //calculating nickels from change
    //if nickels is valid or more than 0 than update remaining change value
    if(nickels>=1)
        change=change-nickels*5;

    //printing output...
    printf("\nChange=>\nDollors: %d\nQuarters: %d\nDimes: %d\nnickels: %d\nPennies: %d",dollors,quarters,dimes,nickels,change);



}

//main
int main()
{
    //variable declaration
    int price , amount;
    //taking inputs
    printf("Enter price and amount: ");
    scanf("%d%d",&price,&amount);
    //function call
    totalCoins(price ,amount);

    return 0;
}

Output:

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
Create a Change application that prompts the user for an amount less than $1.00 and then...
Create a Change application that prompts the user for an amount less than $1.00 and then displays the minimum number of coins necessary to make the change. The change can be made up of quarters, dimes, nickels, and pennies. The application output should look similar to: Enter the change in cents: 212 The minimum number of coins is: Quarters: 8 Dimes: 1 Nickels 0 Pennies: 2 Must be coded in Java please
4) Create the following in a Java program. Create a Scanner Prompt the user to Receive...
4) Create the following in a Java program. Create a Scanner Prompt the user to Receive the amount and declare the variable double amount for scanner Declare variable integer remaining amount which is equal to (int) (amount*100) Find the number of one dollars bt declaring the integer variable which is equal to remaining amount divided by 100 Declare: remaining amount %=100 Find the number of quarters: Declare integer variable number of quarters equal to remaining amount divided by 25 Declare:...
Write a program that reads three integer values from the keyboard using the Scanner class representing,...
Write a program that reads three integer values from the keyboard using the Scanner class representing, respectively, a number of quarters, dimes, and nickels. Convert the total coin amount to dollars and output the result.Write a program that reads three integer values from the keyboard using the Scanner class representing, respectively, a number of quarters, dimes, and nickels. Convert the total coin amount to dollars and output the result.
USE PYTHON Please!!! 4.15 LAB: Exact change Write a program with total change amount as an...
USE PYTHON Please!!! 4.15 LAB: Exact change 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...
Design a Candy Machine which takes Quarters, Dimes and Nickels for releasing a Candy which costs...
Design a Candy Machine which takes Quarters, Dimes and Nickels for releasing a Candy which costs 40 cents. • Input: Q(Quarter), D(Dime),N(Nickel) • Output: Candy released Notation: • Q=Quarters • D=Dimes • N=Nickels Required Output: Candy should be coming out of the machine after receiving an amount greater than or equal to 40 cents. make a state table and a state diagram for this question Extra Credit: Extra credit will be given if you also return change along with candy
CREATE USING A STATE DIAGRAM Design a Candy Machine which takes Quarters, Dimes and Nickels for...
CREATE USING A STATE DIAGRAM Design a Candy Machine which takes Quarters, Dimes and Nickels for releasing a Candy which costs 40 cents and returns change. • Input: Q(Quarter), D(Dime),N(Nickel) • Output: Candy released Candy should be coming out of the machine after receiving an amount greater than or equal to 40 cents.
Using C programming Create a function called printMenu( ) with the following properties: Has no function...
Using C programming Create a function called printMenu( ) with the following properties: Has no function inputs or output. Prints the following menu to the screen: 1. Enter user name. 2. Enter scores. 3. Display average score. 4. Display summary. 5. Quit Create a function called printLine( ) with the following properties: Takes as input a char Takes as input an integer corresponding to the number of times to print the character Has no function output. For example, if we...
program has to be written in X86 processor assy language. Write a program that find the...
program has to be written in X86 processor assy language. Write a program that find the minimum number of coins that can represent an amount of money under $1. The amount of money is a random number between 0 and 99 (cents). The randomRange procedure is used to get a random number. Review the sample code in lab4.asm and run it to see how randomRange works. Each time randomRange is called, it creates a random number between 0 and the...
int truncate(char str[], unsigned int index); Create a function called truncate() that takes a string and...
int truncate(char str[], unsigned int index); Create a function called truncate() that takes a string and integer as a parameter. Your function should truncate the string by placing a NULL byte at the specified index. You should return the index passed as a parameter if successful, -1 on fail. For example, if the index given is 5, but the string is “fun”, you would return -1 because the string is not long enough.
Define a function called ngram_list() that takes a filename and a positive integer n representing the...
Define a function called ngram_list() that takes a filename and a positive integer n representing the number of characters to be displayed on each line (but don't actually display anything in this function — so no print() in this function). The function should return a list of strings, consisting of the contents of the file split into chunks n characters long. If there is an error working with the file, the function should return an empty list. For example, using...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT