English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

hello, to any1 familar with python programing, I'm to do this assigment for comp sci 30, i've been trying for a week still can't get it to run, the assignmet is:

1. Write a program that calculates the number of quarters, dimes, nickels and pennies necessary to generate the number of cents entered as input.

For example, if 93 cents is entered as the input, then the program should indicate that 3 quarters, 1 dime, 1 nickel and 3 pennies are necessary to add up to 93 cents.

i've been given the resource http://www.ibiblio.org/obp/thinkCSpy/
as well as http://rgruet.free.fr/PQR24/PQR2.4.html

the first link is better, can any1 help me, i've managed to get it to work with that def thing but it doesn't save the change value, can any1 help me do something similar? the teacher hinted me, that it was something to do with one while statement, and o buch of other different kinds statements working under it

2006-11-08 16:40:50 · 2 answers · asked by icemaster1500 5 in Computers & Internet Programming & Design

2 answers

int cents = 93

int quarters = (cents - cents%25)/25
cents -= 25*quarters

int dimes = (cents - cents%10)/10
cents -= 10 * dimes

int nickels = (cents - cents%5)/5
cents -= 5 * nickels

This formula (cents - cents%25)/25 is

(cents - the remainder of cents after 25 is divided into it)

Now your left with a number 25 can divide into evenly and then you can divide 75 cents by 25 cents to get the amount of quarters.

2006-11-08 17:21:10 · answer #1 · answered by Anonymous · 0 0

i've got have been given some books on python, yet i in no way have been given around to discovering it yet (sensible for an quite expert simulation software at my paintings) and the books are at my place of work. i'm specific in case you google you will locate some tutorials on line. as on your specific subject, you probably did no longer somewhat clarify it very nicely: "whilst a huge decision is given will supply me the radius" what does the enter extensive type represent?

2016-12-28 16:46:40 · answer #2 · answered by ? 3 · 0 0

fedest.com, questions and answers