hi.
i need to find the average and range of numbers entered by the user.
the user can enter as many terms as possible.
the user should enter a negative number to end.
i was able to do it with "goto".
but i need to do the program using if...else..
here's the code using "goto"
Code:
#include<stdio.h>
#include<conio.h>
int main()
{
int count;
float value,high,low,sum,average,range;
sum = 0;
count = 0;
printf("Enter numbers in a row\n.Enter negative number to end");
input:
scanf("%f",&value);
if(value<0) goto output;
count = count + 1;
if(count == 1)
high = low = value;
else if(value>high)
high = value;
else if(value<low)
low = value;
sum = sum + value;
goto input;
output:
average = sum/count;
range = high - low;
printf("\n\n");
printf("Total values : %d\n",count);
printf("Highest value : %f\nLowest value : %f\n",high,low);
printf("Range : %f\nAverage : %f\n",range,average);
return 0;
}