I have this code that will compute a student's average QPI (Qoutient Percentile Intelligence). You see, the code is too messy. Can anyone help me to make it clean? I mean, help me to make a function that will multiply the grade and the units and divide the product to the total number of units... something like that. Thanks!!! I will gladly appreciate your help and if you have any links that you want me to go, please do tell.
I really need a proffesional's opinion. Hope you'll listen to me.
Code:
#include <stdio.h>
#include <ctype.h>
#include <conio.h>
#define MAXNAME 100
int main(void){
char c, name[MAXNAME];
int i, sub;
float unit, grde, sum, prod, qou, tot;
while((c=getchar()) != 0){
grde=sum=prod=qou=tot=0;
printf("\n\nACADEMIC HONORS COMPUTATION\n");
printf("Complete name of student: \n");
printf("\t");
for(i=0; (c = getchar())!='\n'; ++i){
name[i]=c;
}
name[i]='\0';
printf("Number of subjects: \n");
printf("\t");
scanf("%d", &sub);
for(i=0; i<sub; ++i){
printf("Grade of Subject %d: ", i+1);
scanf("%f", &grde);
printf("Number of units of subject %d: ", i+1);
scanf("%f", &unit);
prod=grde*unit;
sum+=prod;
}
printf("%s has %d subjects.\n", name, sub);
printf("Sum of all is %.2f", sum);
printf("\nEnter total number of units: ");
scanf("%f", &tot);
qou=sum/tot;
printf("\nYour grade is %.2f", qou);
if(qou>=3.70 && qou<=4)
printf("\n%s is qualified for 1st honors\n", name);
else if(qou>=3.25 && qou<=3.69)
printf("\n%s is qualified for 2nd honors\n", name);
else
printf("\n%s is not qualified to become an honor\n", name);
}
getch();
return 0;
}