ok all I'm a new c student. So I need eveeryone who post not to use advanced functions I haven't been instructed in.
here is the homework exercise:

develop a program that will input the miles driven and gallons used for each tankful. the program should calculate and display the miles per gallon obtained for each tankful. after processing all input, the porgram should calculate and print the combined miles per gallon from all tankfuls.

I've got the program to work on the first inputs and it diplays my mpg and then asks for next gallon input. if I do -1 it keeps on asking for next input and never ends giving me a grand total mpg for one or more tankfuls.

here is my code:
Code:
/* miles per gallon on each tank full */
#include <stdio.h>

int main()
{
	int miles; /* miles driven */
	float mpg, gallons, total; /* miles per gallon, gallons used, total of all mpg's */
    int counter; /* the counter */
    
	counter = 0;
	mpg = 0;
	total = 0; /* intitilizing all non user input veriables */
	
	printf ("Enter the gallons used (-1 to end):");
	scanf  ("%f", &gallons); /* user input of the gallons used */

	printf ("Enter the miles driven:");
    scanf  ("%d", &miles ); /* user input of the miles driven */

	mpg = miles / (float) gallons; /* formula to obtian miles per gallon based on inputs */

	printf ("the miles/gallon for this tank was: %.2f\n" , mpg); /* result on first avrage before moving to next prompt*/

	while ( gallons != -1) { /* loop until the input of -1 @ gallons prompt */
        
		total = total + mpg;
       
        counter++; 
		
		
		printf ("Enter the gallons used (-1 to end):");
		scanf  ("%f", &gallons); 
		printf ("Enter the miles driven:");
		scanf  ("%d", &miles );
        printf ("the miles/gallon for this tank was: %.2f\n" , mpg);
		
	} /* end while */

	if ( counter != 0 ) { 
           mpg = ( float ) total / counter; /* grand total */
        
        printf( "The average miles per gallon is %.2f",mpg );
	}/* end if */

	else { /* if no input but -1 was entered */
		printf ("No information entered");
	} /* end else */

	return (0);
}
/* end main */
Remember I'm new and very limited in shortcuts so please use the most basic forms of programming in helping me find the code's problems.

Thanks all,
Joseph