As part of learning more C, I wrote this extremely trivial C program that takes Student scores from stdin
and, upon termination, prints out the minimum score/maximum score and the average score. Can somebody review my code and tell me how I might be able to improve my code?
#include <stdio.h>
int main()
{
int currentEntry;
int startValue = 0;
int counter = 0;
int currentMax;
int currentMin;
double average;
printf("Enter scores one-by-one, exit by entering -1\n");
while(currentEntry != -1){
if((scanf("%d",¤tEntry) == 1) && (currentEntry != -1)){
printf("Current score is %d\n",currentEntry);
counter++;
startValue += currentEntry;
average = startValue/counter;
if(counter == 1){
currentMax = currentEntry;
currentMin = currentEntry;
}
if(currentEntry > currentMax){
currentMax = currentEntry;
}
if(currentEntry < currentMin){
currentMin = currentEntry;
}
}
}
printf("The average is %lf\n",average);
printf("The maximum score is %d\n",currentMax);
printf("The minimum score is %d\n",currentMin);
return 0;
}