Hi so I figured out the water.c problem but aside from the requirements, I want the user to input the positive number only (the program will keep asking the user to input "Minutes: " again and again until a positive value is input) but I can't find the way to do so. Also how to repeat the program automatically again and again until the user want to exit? Here is my code:

#include <stdio.h>
#include <cs50.h>

int main(void)
    printf("Minutes: ");
    int Minutes = GetInt();
    int Bottles;
    Bottles = Minutes * 12;
        printf("Bottles: %i\n", Bottles);
        return 0;
    while(Minutes >= 1);
    while(Minutes == 0)
        printf("Bottles: 0");

So effectively this is what you want to do to ensure that the user can only input positive numbers:

// while the number of minutes is less than 1
    // keep asking the user for minutes

The 'while' is a big hint, but ask away if you need help putting this pseudocode into actual code.


To force the user to enter a specific number, use a while or do-while loop that checks the value of minutes.

While checking if the number is greater than 0, if the user doesn't comply, you you just add a return statement after the while loop.

You must log in to answer this question.

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