For some reason, I can't get scanf to work. I did it just like the book said. Try it. I'm supposed to enter (FirstInitial)(LastInitial)Grade
Ex: TB100 For Tom Brady got a 100.
It reads:
FirstInitial: NOTHING
LastInitial: T
Grade:0
Then it skips to the second student and did this
FirstInitial: B
LastInitial: NOTHING
Grade: 100
HELP!!
#include <stdio.h>
//#include <string.h>
int Sum_Total=0;
int Average_Highest=0;
int Grade_Max=0;
int Count_Total_Students=0;
int Classes[4];
int main(void)
{
/*Each students. data consists of a first and last initials and
1 exam score (0..100)* */
//Create Classes
int i=0;
char fi0;
char li0;
double grade0=0;
double class0=0;
double ClassAvg[4]={0,0,0,0};
double ClassGrade[4]={0,0,0,0};
char fia[4];
char lia[4];
for (i=0;i<4;i++)
{
double sum=0;
printf("How many students are in class %d?\n",(i+1));
int t=0;
scanf("%d",&t);
//int Students[t];
char fi='a';
char li='a';
double grade=0;
int z=0;
for (z=0;z<t;z++)
{
printf("Enter student %d's data. Ex:TC100 (Tom Brady has a 100) :: ",(z+1));
char fi2='a';
char li2='a';
double grade2=0;
scanf("%c%c",&fi2,&li2);
printf("\nFIRST INITIAL:%c - LAST INITIAL:%c",fi2,li2);
printf("\n");
scanf("%d",&grade2);
if (grade2>grade)
{
grade=grade2;
fi=fi2;
li=li2;
}
printf("\n");
printf("FI:%c LI:%c GR:%d\n",fi2,li2,grade2);
sum=sum+grade2;
}
if (grade>grade0)
{
grade0=grade;
li0=li;
fi0=fi;
class0=i;
}
ClassAvg[z]=(sum/t);
ClassGrade[z]=grade;
fia[z]=fi;
lia[z]=li;
}
//Computations
double TotalAvg=ClassAvg[0]+ClassAvg[1]+ClassAvg[2]+ClassAvg[3];
TotalAvg=TotalAvg/4;
printf("-CLASS CALCULATIONS-\nTotal Classes:4\nTotal Average of All Classes::%d\nHighest Grade was a %d made by %c.%c. in Class %d",TotalAvg,grade0,fi0,li0,class0);
printf("\n[CLASS1]\nClass Average:%d\nHighest Score by %c.%c.::%d",ClassAvg[0],fia[0],lia[0],ClassGrade[0]);
printf("\n[CLASS2]\nClass Average:%d\nHighest Score by %c.%c.::%d",ClassAvg[0],fia[1],lia[1],ClassGrade[1]);
printf("\n[CLASS3]\nClass Average:%d\nHighest Score by %c.%c.::%d",ClassAvg[0],fia[2],lia[2],ClassGrade[2]);
printf("\n[CLASS4]\nClass Average:%d\nHighest Score by %c.%c.::%d",ClassAvg[0],fia[3],lia[3],ClassGrade[3]);
return 0;
}