When I am prompted for change, if I type in a negative number it goes like this:

How much change are you owed?  
jharvard@appliance (~/pset1): 

It doesn't have any reaction, even though I have the beginning of my program like this:

#include <stdio.h>
#include <cs.50.h>
#include <math.h>

int main(void)
printf{"How much change are you owed?\n"}
int coins = 0
float money = GetFloat();

if (money > 0) {

    while (money < 0)  {
    printf("Retry: ");
    money = GetFloat();

Also, check50 says something like this:

:( rejects input of -.1
should reject, not have an exit of 0.

What should I do? Should I leave it, but if I do, why isn't my code in my program working? Thanks in advance, please answer ASAP.

  • Your code displays the prompt "How much change are you owed?" but that section of code is not shown in your question. It's clear that the problem is not in the short section of code that you posted, but elsewhere. Please edit the code and add the relevant code.
    – Cliff B
    Dec 30 '15 at 18:52

You put the while loop that handles money < 0 inside an if statement code block where the if statement tests if money > 0. The code will only get to the while statement when money is greater than 0, so it is impossible for the while statement to ever see money < 0. The while loop code block is dead code (code that never executes) because of the if statement.

If you remove the if statement and the curly braces {} surrounding the while loop, it should work.

If this answers your question, please click on the check mark to accept. Let's keep up on forum maintenance. ;-)

  • Thank you so much! It really helped! :)
    – sophiemath
    Dec 30 '15 at 20:54

You must log in to answer this question.

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