I'm solving CS50 (problemset 1) i.e water.c. It asks user to write a program that prompts the user for the length of his or her shower in minutes (as a positive integer) and then prints the equivalent number of bottles of water (as an integer). 1 min of shower = 12 bottles consumed MAIN PROBLEM: The problem is that we have to ensure that the user inputs a positive number of minutes otherwise it keeps on re-prompting his back to input/scanf statement. As long as he enters he enters length<=0, I can re-prompt him back using while(length<=0) condition but as he enters a character i.e abc123 in input my code keeps on executing. Any solutions??
>
 #include <stdio.h>
 int main()
 {   int length=0;
    int min=12;
    int bottle=0;
    printf("Enter length of his or her shower in minutes");
    scanf("%d", &length);
    while (length <= 0){
    printf("Enter length of his or her shower in minutes");
    scanf("%d", &length);
    }
    bottle= (min*length);
    printf("%d", bottle);
    return 0;
 }
 
     
     
     
    