So, I made this basic loop to take user input, do some calculations with it and then after the loop breaks to display the overall average of the calculations. The problem is with the warning I am getting. Maybe I am missing something here, but I am new to this, so I don't know what the issue is. The first warning says, "Variable 'miles' is used uninitialized whenever function 'main' is called." The second warning says, "Variable 'gallons' may be uninitialized when used here." The program seems to work fine, but I just don't know how to fix the warnings. Any help is appreciated.
#include <stdio.h> //library header
int main() { //declare main function
double gallons,miles;
double sum=0;
int count=0;
while (miles>=0||gallons>=0) {
sum+=(miles/gallons);
count++;
printf("\nEnter the gallons used (-1 to end): ");
scanf("%lf",&gallons);
if (gallons<0)
break;
printf("Enter the miles driven: ");
scanf("%lf",&miles);
if (miles<0)
break;
printf("The miles/gallon for this tank was: %lf", miles/gallons);
}
if (count>0) {
printf("The average is: %lf", sum/(count-1));
}
return 0;
}