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;
}