This is a simple program for a class that prompts the user for the length of his or her shower in minutes (as a positive integer, re-prompting as needed) and then prints the equivalent number of bottles of water (as an integer).
It assumes the shower uses 1.5 gallons of water per minute (192 oz) and a plastic bottle size of 16 oz
My do-while loop successfully rejects negative numbers and 0, however, if I input text such as "foo" when prompted for the length of a shower in minutes, the program runs into an infinite loop, forever running the loop and printing "How long is your shower(in minutes)?:"
Any ideas how to refine the while condition to avoid this?
#include <stdio.h>
int min_to_bottles(int *n);
int main(void)
{
    int minutes;
    int bottles;
    do
    {
        printf("How long is your shower(in minutes)?:");
        scanf("%i", &minutes);
    }
    while (minutes < 1);
    bottles = min_to_bottles(&minutes);
    printf("Equivalent of bottles used per shower is: %i\n", bottles);
}
int min_to_bottles(int *n)
{
    int bottles;
    int oz = 192 * *n;
    bottles = oz/16;
    return bottles;
}
 
     
     
     
    