![]() |
|
|
|
| ||||||
|
Welcome to the The ProgrammersTalk Community forums. You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today! If you have any problems with the registration process or your account login, please contact contact us. |
| Tags: |
![]() |
![]() | | LinkBack | Thread Tools | Display Modes | ![]() |
| |||
| [SOLVED] Need help with a Python programming assignment? 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 |
| |
| |||
| 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. |
![]() |
| Thread Tools | |
| Display Modes | |
| |