Hello to all,
I'm doing some tweaks to a previously written code and I am struggling to change an input. Written in C lang., the code is used to get the average test scores as the user inputs them. The tricky part is that the program is written to eliminate only the lowest score. How can I change it so it eliminates any amount of test scores the user wishes to eliminate?
Any help or advice given will be of great assistance. Thank you beforehand.
#include <stdio.h>
#include <limits.h>
int main()
{
int a = 0;
double temp = INT_MAX, ExamValue = 0, Earray[200] = {0}, ExamValueTotal = 0, StudentGradeTotal = 0, Average = 0, Garray[200] = {0};
printf("\n\n\t Program to determine final grade of student.");
printf("\n\n\t Enter the Exam's Value to begin. \n\n\t Then enter the student's grade on it.\n\n\t When finished, enter in Exam's Value a -1.",162,160);
while (ExamValue >= -0.000001){
printf ("\n\n\t Exam's Value: ");
scanf ("%lf",&ExamValue);
if (ExamValue > -0.000001){
printf ("\n\n\t Student's grade: ",162);
scanf ("%lf",&Garray[a]);
Earray[a] = ExamValue;
a++;
}
}
if(a != 1){
int x,y;
for(x = 0; x < a; x++){
if((Garray[x]/Earray[x]) < temp){
temp = (Garray[x]/Earray[x]);
y = x;
}
}
while(a > -1){
if(a != y){
StudentGradeTotal += Garray[a];
ExamValueTotal += Earray[a];
}
a--;
}
}else{
while(a > -1){
StudentGradeTotal += Garray[a];
ExamValueTotal += Earray[a];
a--;
}
}
if (ExamValueTotal > 0){
Average = StudentGradeTotal/ExamValueTotal * 100;
}
else{
printf ("\n\n\t The Exam's Value is 0.\n\n\t Therefore there is no grade for the student.\n\n\t ");
return 0;
}
printf ("\n\n\t The Average is: %lf",Average);
printf ("\n\n\t THe final grade is: ");
if (Average < 60)
printf ("F");
else if (Average < 70)
printf ("D");
else if (Average < 80)
printf ("C");
else if (Average < 90)
printf ("B");
else
printf ("A");
printf ("\n\n\t ");
return 0;
}
I'm doing some tweaks to a previously written code and I am struggling to change an input. Written in C lang., the code is used to get the average test scores as the user inputs them. The tricky part is that the program is written to eliminate only the lowest score. How can I change it so it eliminates any amount of test scores the user wishes to eliminate?
Any help or advice given will be of great assistance. Thank you beforehand.
#include <stdio.h>
#include <limits.h>
int main()
{
int a = 0;
double temp = INT_MAX, ExamValue = 0, Earray[200] = {0}, ExamValueTotal = 0, StudentGradeTotal = 0, Average = 0, Garray[200] = {0};
printf("\n\n\t Program to determine final grade of student.");
printf("\n\n\t Enter the Exam's Value to begin. \n\n\t Then enter the student's grade on it.\n\n\t When finished, enter in Exam's Value a -1.",162,160);
while (ExamValue >= -0.000001){
printf ("\n\n\t Exam's Value: ");
scanf ("%lf",&ExamValue);
if (ExamValue > -0.000001){
printf ("\n\n\t Student's grade: ",162);
scanf ("%lf",&Garray[a]);
Earray[a] = ExamValue;
a++;
}
}
if(a != 1){
int x,y;
for(x = 0; x < a; x++){
if((Garray[x]/Earray[x]) < temp){
temp = (Garray[x]/Earray[x]);
y = x;
}
}
while(a > -1){
if(a != y){
StudentGradeTotal += Garray[a];
ExamValueTotal += Earray[a];
}
a--;
}
}else{
while(a > -1){
StudentGradeTotal += Garray[a];
ExamValueTotal += Earray[a];
a--;
}
}
if (ExamValueTotal > 0){
Average = StudentGradeTotal/ExamValueTotal * 100;
}
else{
printf ("\n\n\t The Exam's Value is 0.\n\n\t Therefore there is no grade for the student.\n\n\t ");
return 0;
}
printf ("\n\n\t The Average is: %lf",Average);
printf ("\n\n\t THe final grade is: ");
if (Average < 60)
printf ("F");
else if (Average < 70)
printf ("D");
else if (Average < 80)
printf ("C");
else if (Average < 90)
printf ("B");
else
printf ("A");
printf ("\n\n\t ");
return 0;
}