Common I corrected it in my most recent code and in this one I am posting for laserlight. I think I found the solution to my problem I just added a sum-=num before the break so that way it adds whatever negative number the user enters to break the loop. So as of now I am able to input test scores terminate the program with any number and then print the average. My next step is just to print the high/low scores. Where should I start with that? laserlight will the code I have below work? I understand there are a multitude of different ways to write code and Im sure yours is much better than mine but I am still learning so if the way I have it will work I would like to keep it that way, but if it is not correct please let me know.
Code:
int main(void)
{
float i;
int num,sum, avg, high, low;
printf("Enter test scores (-1 to terminate list)\n");
sum=0;
i=0;
while (1)
{
scanf("%d", &num);
sum += num;
if (num<0)
{
sum-=num;
break;
}
i=i+1;
}
printf("Sum: %d\n",sum);
printf("Average: %0.2f\n", sum/i);
}
Here is a trial run
Enter test scores (-1 to terminate list)
87
54
92
73
-20
Sum: 306
Average: 76.50