I really need guidance on an assignment.
Instructions
In this case i suggest you should you while or do while loop, you cannot use for loop if do not know the destination
#include <stdio.h>
int main()
{
int count = 0;
float sum = 0;
float numbers;
printf("Enter numbers to find the average (0 to stop)\n");
do {
scanf("%f", &numbers);
count++;
sum += numbers;
} while(numbers != 0);
printf("Result: %f", sum/(count-1));
return 0;
}
the following proposed cleanly compiles and performs the desired functionality
#include <stdio.h>
int main( void )
{
int counter;
int sum = 0;
int numbers;
printf("Enter numbers to find the average (0 to stop)\n");
for ( counter = 0; ; counter++)
{
scanf("%d", &numbers);
if( ! numbers )
break;
sum += numbers;
}
float fcounter = (float)counter;
float fsum = (float)sum;
float average = fsum / fcounter;
printf("\nAverage = %.3f", average);
return 0;
}