Input to Eliminate Test Scores on Program

Hector3436

Honorable
Sep 5, 2012
5
0
10,510
0
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;
}
 

Scott_D_Bowen

Honorable
Nov 28, 2012
50
0
10,590
1
[cpp]while (ExamValue >= -0.000001){ [/cpp] 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).

[cpp]while (ExamValue > 0){ [/cpp] 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.
 
Thread starter Similar threads Forum Replies Date
Y Apps General Discussion 1
A Apps General Discussion 3
S Apps General Discussion 2
R Apps General Discussion 3
I Apps General Discussion 2
E Apps General Discussion 1
S Apps General Discussion 1
S Apps General Discussion 3
F Apps General Discussion 3
Rainfire Apps General Discussion 3
A Apps General Discussion 6
P Apps General Discussion 5
FlamingFox Apps General Discussion 1
B Apps General Discussion 3
P Apps General Discussion 3
J Apps General Discussion 1
M Apps General Discussion 1
M Apps General Discussion 6
shiftyape Apps General Discussion 3
S Apps General Discussion 1
Similar threads
Write a program to calculate commission for the input valu of sales amount
Getting keyboard input through microfone
I don't have steam but I have origin and I've downloaded a few games (i had a disc input on my old computer) on my first compu
Installed Equalizer APO and now discord wont detect microphone input
1. Write a program that outputs the greatest common divisor of two positive integers. For example, if you input two positive
Gmail response input problems...
How to take user input of one form and assign it to a variable in another form in java?
How to compare user input in a jTextfield with data in the database? (im using java & php)
Having input trouble with a personal Java project
How do I make a yes or no question with different outcomes depending on input?
3. Write a C# application that asks the user to input ‘A’ and ‘B’ and prints the sum of squares of all even numbers be
Asus Tweaker is causing my monitor to display "input not supported"
[Survey] Wanting Input on Media Players
Batch file to open app, and input commands.
input the roman numerals from text file and convert it into arabic and again write it into text file in java
I need a program that takes HTML file as input and convert it to hypertree of webOQL type. You may consider a simple HTML file
How can I get Speedfan to work constantly without any user input?
Write a program that reads 3 integers as input and prints the second largest of these three numbers. Example: Input: 3 4 5 Out
c++ how to advance if dont get input
After Effects Text Input

ASK THE COMMUNITY