Question

Write a script called makeChange that prompts the user for a monetary amount in cents less...

Write a script called makeChange that prompts the user for a monetary amount in cents less than or equal to 99 cents (i.e. less than a loonie) and then prints how change would be made for that amount out of quarters (25-cent coins), dimes (10-cent coins), nickels (5-cent coins) and pennies (1-cent coins). The change your script specifies should be the minimum number of coins. For example, when making change for 88 cents, the result should indicate 3 quarters, 1 dime and 3 pennies. When done, your script should also ask the user if she would like to make change again. If the user enters y (or Y), the script should repeat. Here are three sample runs. Your script should run as follows (what I enter is in bold):

$ makeChange
Please enter an amount less than 100 (i.e. <=99 cents): 125
125 exceeds 99 cents. Try again: 109
109 exceeds 99 cents. Try again: 89
Your change is:
3 quarter(s)
1 dime(s)
4 pennie(s)
Would you like to make change again? y
Please enter an amount less than (i.e. <=99 cents): 144
144 exceeds 99 cents. Try again: 75
Your change is:
3 quarter(s)
Would you like to make change again? Y
Please enter an amount less than (i.e. <=99 cents): 93
Your change is:
3 quarter(s)
1 dime(s)
1 nickel(s)
3 pennie(s)
Would you like to make change again? Y
Please enter an amount less than (i.e. <=99 cents): 24
Your change is:
2 dime(s)
4 pennie(s)
Would you like to make change again? n
$

Hint: Use the % operator with expr to determine the remainder of dividing one number into another number. You will need to use the if and while commands.

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

BASH SCRIPT:

#!/bin/bash
again="y"
while [ $again == "Y" -o $again == 'y' ]
do
        echo -n "Please enter an amount less than 100: "
        read amount
        # Validate user input
        while [ $amount -ge 100 ]
        do
                echo -n "$amount exceeds 99 cents. Try again: "
                read amount
        done
        # Calculate changes
        quarters=`expr $amount / 25`
        dimes=`expr $amount % 25 / 10`
        nickels=`expr $amount % 25 % 10 / 5`
        pennies=`expr $amount % 25 % 10 % 5`
        # Display changes, if any coin is 0 then do not display it
        echo "Your change is:"
        if [ $quarters -gt 0 ]; then
                echo "$quarters quarter(s)"
        fi
        if [ $dimes -gt 0 ]; then
                echo "$dimes dime(s)"
        fi
        if [ $nickels -gt 0 ]; then
                echo "$nickels nickel(s)"
        fi
        if [ $pennies -gt 0 ]; then
                echo "$pennies pennie(s)"
        fi
        # Ask the user if he/she wants to continue
        echo -n "Would you like to make change again? "
        read again
done

SAMPLE OUTPUT:

Add a comment
Know the answer?
Add Answer to:
Write a script called makeChange that prompts the user for a monetary amount in cents less...
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
  • I need to change this python program into one that counts back the LEAST AMOUNT OF...

    I need to change this python program into one that counts back the LEAST AMOUNT OF COINS. Ex: if i input 44 as my change, how can i make it show 4 dimes and 4 pennies instead of 1 quarter, a dime, and 9 pennies? heres my code so far in PYTHON " cents=int(input("Please enter the change in Cents: ")) Quarter= int(cents/25)#25cents=1 Quarter Dime =int (cents%25/10)# 10 cents=1 Dime cents =(cents%25)%10 print(Quarter,"quarters",Dime,"dimes and",cents,"cents") "

  • Write a program that tells what coins to give out for as change from 1 cent...

    Write a program that tells what coins to give out for as change from 1 cent to 99 cents. Use coin denominations of 25 cents (quarters), 10 cents (dimes), and 1 cent (pennies) only. Include a loop that lets the user repeat this computation for new input values until the user says he or she wants to end the program. Solution Demo Hello I am the coin machine! I will give you the least number of coins for your change....

  • in c code x Global Soccer 1.docx x Acceleration Due to 6 x M Inbox (5,949)...

    in c code x Global Soccer 1.docx x Acceleration Due to 6 x M Inbox (5,949) - joshfor x M Inbox (4,224) - joshuar X ® AC ads/ACFrOgA6UB 1k4Z1i1xGLNQ1Lntj510 lutEUaA..pdf ECE 175: Computer Programming for Engineering Applications Lab Assignment #2 (Thursday sessions) Relevant Programming Concepts: • Branch Structure • Loop Problem 1 (15 points): Develop a C program that asks a user to enter a total change amount in cents) and outputs the change using the fewest coins. The coin...

  • 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...

  • Can you please help me with creating this Java Code using the following pseudocode? Make Change C...

    Can you please help me with creating this Java Code using the following pseudocode? Make Change Calculator (100 points + 5 ex.cr.)                                                                                                                                  2019 In this program (closely related to the change calculator done as the prior assignment) you will make “change for a dollar” using the most efficient set of coins possible. In Part A you will give the fewest quarters, dimes, nickels, and pennies possible (i.e., without regard to any ‘limits’ on coin counts), but in Part B you...

  • All items at a "Penny Fair" are priced less than $1.00. Write a program that makes...

    All items at a "Penny Fair" are priced less than $1.00. Write a program that makes change with a minimum number of coins when a customer pays for an item with a one dollar bill. Prompt for the item price in cents, report the change due, and the number of coins of each denomination required. Use only quarters, dimes, nickels, and pennies for change (no 50 cent pieces). See sample output but your program should work for any item price....

  • you are designing a matlab script that will function as an automated cash regisiter. the cash...

    you are designing a matlab script that will function as an automated cash regisiter. the cash register will recive two inputs,the price of an item in cents, and the amount of cents payed by the customer. the cash register will then dispense change using the highest denominations of currency available ranging from 1 dollar bill to a penny dollar = 100 cents quarter =25 cents dime= 10 cents nickel=5 penny=1 cent your program should ensure that the highest available denomiation...

  • Cathy is a part-time cashier who works at a convenience store somewhere in Canada. She needs...

    Cathy is a part-time cashier who works at a convenience store somewhere in Canada. She needs a C program to find out the minimum number of coins when making change for n cents, where 0 ≤ n ≤ 99. The following shows an anticipated case of interaction when using the software. Please enter the amount for change in the range from 0 to 99 cents: 94 The change is 3 quarter(s), 1 dime(s), 1 nickel(s), and 4 penny/pennies. The C...

  • (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...

  • You are writing a Python script that prompts a user to guess the current contents of...

    You are writing a Python script that prompts a user to guess the current contents of a variable called temperature (assume previously set, and not shown). What is the missing statement? guess = float(input("Please enter your guess ")) ____________________________    # Fill in the missing line of code      print ("You're right!") else:      print ("Please try again") You are writing a Python script that prompts a user to guess the current contents of a variable called temperature (assume previously set,...

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
ADVERTISEMENT