0

import cs50

while True:

    print ("O! Hail!, How Much Change Is Owed?")

    n = cs50.get_float()

    if n >= 0:

        break

    q = 25
    q1 = 0
    d = 10
    d1= 0
    ni = 5
    ni1 = 0
    p = 1

    nocq = 0

    nocd = 0

    nocni = 0

    nocp = 0

    change = 0

    count = 0

    change = round (n * 100)

    if change >= q:

        q1 = change % q

        nocq = round ((change - q1) / q)

        count = nocq

        if q1 >= d:

            d1 = change % d

            nocd = round ((q1 - d1) / d)

            count = count + nocd

    elif change < q and change >= d:

        d1 = change % d

        nocd = round ((change - d1) / d)

        count = count + nocd

        if d1 >= ni:

            ni1 = change % ni

            nocni = round((d1 - ni1) / ni)

            count = count + nocni

    elif change < d and change >= ni:

        ni1 = change % ni

        nocni = round ((change - ni1) / ni)

        count = count + nocni

        if q1 < d1 and q1 < ni:

            q1 = p

            if d1 < ni1:

                d1 = p

    elif change < q and change < d and change < ni:

        change = p

        count = count + p

    print (count)

    print ()
  • To properly format this code: edit the question, select the code, click the {} in the format bar. – DinoCoderSaurus Mar 29 '17 at 11:05
1
if n >= 0:      
      break

This breaks you out of the While loop, so your program simply ends if the user gives you a positive number.

| improve this answer | |
  • @Curioskiwi, my logic is: as long a the user continues to supply a number less than 0, the program will continue to prompt for input. As soon as a number greater than 0 is supplied, it jumps out of the loop to access the other parts of the program. I think I'm right on that. My problem is why it doesn't print the result. Improper indentation? Please, someone help! – doublestanding Mar 30 '17 at 12:34
  • @curiouskiwi is correct. The code after your while loop is indented, thus making ALL your code part of the while loop. If your intention is to make something resembling a do/while loop, simply un-indent the rest of your code. :-) – SuperNovaCoder Mar 30 '17 at 13:14
  • Thanks, @Curiouskiwi, but if I make it: if n < 0:, it repeatedly continues to prompt for input. What do I do? – doublestanding Mar 30 '17 at 13:47
  • @Curiouskiwi, et al thanks a million! You were right! It's printing now, the problems remaining now are just that of logic which I will sort on my own. Thanks, once again, (that is 1m + 1 now!!!). Lol!! – doublestanding Mar 30 '17 at 14:03

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .