103,019 views
28 votes
28 votes
mips Write a program that asks the user for an integer between 0 and 100 that represents a number of cents. Convert that number of cents to the equivalent number of quarters, dimes, nickels, and pennies. Then output the maximum number of quarters that will fit the amount, then the maximum number of dimes that will fit into what then remains, and so on. If the amount entered is negative, write an error message and quit. Amounts greater than 100 are OK (the user will get many quarters.) Use extended assembly instructions and exception handler services.

User Achie
by
2.4k points

1 Answer

8 votes
8 votes

Answer:

Step-by-step explanation:

The following code is written in python and divides the amount of cents enterred in as an input into the correct amount of quarters, dimes, nickels and pennies. Finally, printing out all the values.

import math

#First we need to define the value of each coin

penny = 1

nickel = 5

dime = 10

quarter = 25

#Here we define the variables to hold the max number of each coin

quarters = 0

dimes = 0

nickels = 0

pennys = 0

cents = int(input("Please enter an amount of money you have in cents: "))

if cents > 0 and cents <= 100:

if cents >= 25:

quarters = cents / quarter

cents = cents % quarter

if cents >= 10:

dimes = cents/dime

cents = cents % dime

if cents >= 5:

nickels = cents /nickel

cents = cents % nickel

if cents > 0:

pennys = cents / penny

cents = 0

print("The coins are: "

"\\Quarters", math.floor(quarters),

"\\Dimes", math.floor(dimes), "\\Nickels", math.floor(nickels), "\\Pennies", math.floor(pennys))

else:

print("wrong value")

mips Write a program that asks the user for an integer between 0 and 100 that represents-example-1
User MultiGuy
by
3.5k points