46.7k views
5 votes
Write a program that determines the value of the coins in a jar and prints the total in dollars and cents. Read integer values that represent the number of quarters, dimes, nickels, and pennies. This program will require user input.

1 Answer

1 vote

Answer:

The programming language is not stated. To answer this question, I'll make use of python programming language.

The following units of conversions is used in this program

1 quarter = $0.25

1 dime = $0.10

1 nickel = $0.05

1 penny = $0.01

$1 = 100 cents

This program makes use of few comment (See explanation for line by line explanation)

Having listed the above, the program is as follows:

#prompt user for inputs

quarters = int(input("Number of Quarters: "))

dimes = int(input("Number of Dimes: "))

nickels = int(input("Number of Nickels: "))

pennies = int(input("Number of Pennies: "))

#Convert coins to dollars

dollar = 0.25 * quarters + 0.10 * dimes + 0.05 * nickels + 0.01 * pennies

print("Dollar Equivalent")

print(str(round(dollar,2))+" dollars")

cent = dollar * 100

print("Cent Equivalent")

print(str(round(cent,2))+" cents")

Step-by-step explanation:

This first line is a comment

#prompt user for inputs

This line prompts user for value of quarters in the jar

quarters = int(input("Number of Quarters: "))

This line prompts user for value of dimes in the jar

dimes = int(input("Number of Dimes: "))

This line prompts user for value of nickels in the jar

nickels = int(input("Number of Nickels: "))

This line prompts user for value of pennies in the jar

pennies = int(input("Number of Pennies: "))

Using the coin conversion listed in the answer section, the user inputs is converted to dollars in the next line

dollar = 0.25 * quarters + 0.10 * dimes + 0.05 * nickels + 0.01 * pennies

The string "Dollar Equivalent" is printed using the next line

print("Dollar Equivalent")

This line prints the dollar equivalent of the converted coins

print(str(round(dollar,2))+" dollars")

Using the coin conversion listed in the answer section, the user inputs is converted to cents in the next line

cent = dollar * 100

The string "Cent Equivalent" is printed using the next line

print("Cent Equivalent")

This line prints the cent equivalent of the converted coins

print(str(round(cent,2))+" cents")

Please note that the dollar and cent equivalents are rounded to two decimal places. Even though, it's not a requirement of the program, it's a good programming practice

User NewTag
by
3.8k points