Hihi, everyone. Please take a look at my coding and help me fix two things.
First, my 'try again' part is supposed to go back to the original student number count instead of moving to a next student. I think I'm using the loop wrong, but not sure how to fix it. I tried putting the loop outside of my 'for (i=1;i<11;i++)', but it didn't work.
Second, my min and avg work fine, but not max. It keeps giving me a random number and I don't know why.
Thank you so much.
#include<stdio.h>
void main() {
int i,a[10],max=a[0],min=a[0],avg,sum=0;
printf("please input student score one at a time.\n");
for (i=1;i<11;i++) {
printf("Student %d : ",i);
scanf("%d",&a[i]);
while (a[i] > 100 || a[i] < 0) {
printf("Try again!\n");
i-1//im trying to keep the same student count after 'try again'
break;
}
if (max < a[i]) max = a[i];
if (min > a[i]) min = a[i];
sum+=a[i];
}
avg=sum/10;
printf("\n***************final result ***************\n");
printf(" The maximum score is %d\n",max);//only my max is broken. min & avg works fine
printf(" The minimum score is %d\n",min);
printf(" The average score is %d",avg);
getch();
}