/ Sign-up
Your question

Input to Eliminate Test Scores on Program

  • Programming
  • Apps
Last response: in Apps General Discussion
January 13, 2013 11:28:02 PM

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;
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];
while(a > -1){
StudentGradeTotal += Garray[a];
ExamValueTotal += Earray[a];
if (ExamValueTotal > 0){
Average = StudentGradeTotal/ExamValueTotal * 100;
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");
printf ("A");

printf ("\n\n\t ");
return 0;

More about : input eliminate test scores program

January 19, 2013 1:08:03 PM

  1. while (ExamValue >= -0.000001){
is really bad coding practice as you don't really get a guarantee on the precision of floating point in C. In fact, you're not even guaranteed that the loop is going to be handed the type your expecting (a float in this case with a certain precision/accuracy).

  1. while (ExamValue > 0){
would make a much better start.

Because I noticed this first I am going to say what Ijack has said on similar posts.

"Perhaps you should speak to your tutor."

If you're still stuck on it consider reading it just 5 lines at a time, and thinking about what each line really does.

C can be a little bit terse, but it is certainly not a bad place to start learning how to code basic console apps.

How can I change it so it eliminates any amount of test scores the user wishes to eliminate?
- Maybe you need to ask the user for input, check that input is clean, clear any other garbage from the input stream (or C equivalent, I'm speaking C++ here), and then use that in a sentinel controlled loop? (hint).

We're not meant to post solutions, but the odd tip to help someone get started is permitted.