Here is the instructions Write a c++ program that takes six test scores as input and stores them in an array. It
drops the lowest score, and computes the average of the remaining five scores. It outputs
the average score
and here is what I got. I have the lowtest score wrong somehow but not sure what the problem is.......
#include <iostream>
#include <iomanip>
usingnamespace std;
float lowest;
float i;
double avg;
float grades;
float Score1;
float Score2;
float Score3;
float Score4;
float Score5;
float testScore;
float lowScore;
int sz=5;
//Function Prototype
void getScore();
void findLowest( int testScore[], int sz );
void calcAverage ( );
void getScore()
{
float Score1, Score2, Score3, Score4, Score5;
cout << "Enter in 5 test scores and I will store ";
cout << "them in variables. ";
cin >> Score1 >> Score2 >> Score3 >> Score4 >> Score5;
cout << fixed << showpoint;
}
void findLowest( float testScore[], int sz )
{
float lowest = testScore[0]; // make the first element of the array the lowest.
/* loop through the array and compare the rest with
first element.
*/
for ( int i = 0; i < sz; i++ )
{
if ( testScore[i] < lowest )
{
lowest = testScore[i];
}
}
cout << "The lowest is " << lowest << endl;
}
void calcAverage()
{
for ( float i = 0.0; sz < i; i++ )
{
if ( i > lowest )
{
i*= (float (Score1), float (Score2), float (Score3), float (Score4));
avg = (i)/4.0;
}
}
cout << "The Average is " << avg << endl;
}
int main( )
{
cout << "Using Functions ";
cout << "to calculate the average of a series of functions.";
getScore();
// here is my error//;
findLowest()float testScore(i*), int sz );
calcAverage();
cout << "calculate the average of a ";
cout << "series of functions.";
#pragma region wait
cout<<" Press Enter to Quit";
cin.ignore();
cin.get();
#pragma end region
return 0;
it is saying that c:\lab 8 is not recognized as and internal or external command
Thanks for doing that - it makes it easier. Although I meant you to post the compiler output in full
And it would be better if it was indented properly - are you using an IDE? If so it can do this automatically.
OK, there is no need to have 5 float variables (and 5 more unrelated ones in the function) if you have an array of them, but you haven't declared the array - even though you use it in your functions.
You need to get the concept of using a for loop to get input - what if you had lots of numbers? Are you going to have lots of variables?
Also function calls.
There are lots of conceptual problems - best to do some reading :
I need to change the string raptor_prompt_variable_zzyz; to another variable but I am not sure what I am suppost to change it to can anyone help me figure out what variable I need to change it to
One way of doing it - not the best in this situation:
1 2 3 4
while (ScoreIndex<6) {
//your code here
}
If the size of the array is known, you could use a for loop instead - this is the normal way of processing arrays:
1 2 3 4 5 6 7 8 9 10 11
constunsignedshort SIZE = 6;
int GradeArray[SIZE];
unsignedshort Count;
for (Count=0;Count<SIZE;Count++) {
//your code here
}
Even better, you can use a vector, then you don't have to worry about specifying the size, just use push_front (keeps the input order) to insert new values. You can still refer to individual elements using the at function. Read about it:
But that doesn't compile does it? You cannot declare functions inside functions. Did you understand what I said about declaring functions before main with definitions after main?
There a quite a few concepts you are not getting at the moment.
Did you understand what I said about declaring functions before main with definitions after main?
Did you see what I was saying about using a for loop?
With this:
1 2
scoreIndex =7;
if (scoreIndex>6) break;
Not making sense, is it?
And this one? Average =(Total+0.0)/5;
Have a go at fixing these things, and we can look at your code then.