need help with some code

i have three things wrong with this code and cannot figure it out. A hint would be nice. Thanks
1) i need to display the grade inside the summary beside the result.look at comment below
2) calc_average does not work. i have to use a procedure
3) find_lowest does not work but find_highest does.


#include <iostream>
#include <iomanip>
#include <string>


using namespace std;

void determine_grade(double);
double calc_average(double[], double);
double find_lowest(double[], int);
double find_highest(double[], int);

int main()
{
const int GRADE_RESULT = 9;
double grade[GRADE_RESULT];
int count;
int average;
int highest;
int lowest;
int dg;


cout << fixed << showpoint << setprecision(2);

for (count = 0; count < GRADE_RESULT; count++)
{
cout << "Enter result " << (count + 1) << " (or -1 if no more result): ";
cin >> grade[count];


if (grade[count] == -1)
{
break;
}
else if (grade[count] <= -2 || grade[count] > 100)

{
cout << "Invalid Input\n";
(--count);
}
else if (grade[count] >= 0 || grade[count] <= 100)
{
determine_grade(grade[count]);
cout << "will be assigned to this result.";
cout << endl;
}
}

cout << "Summary of the results: " << endl;
for (count = 0; count < grade[count]; count++)
{

cout << " Result " << (count + 1) << ": " << grade[count] << " " << determine_grade<< endl; // PUTTING determine_grade does not work. i need the grade displayed there.

}
average =calc_average(grade, GRADE_RESULT);
cout << "The average of the result is " << average << endl;

highest = find_highest(grade, GRADE_RESULT);
cout << "The highest of the result = " << highest << endl;

lowest = find_lowest(grade, GRADE_RESULT);
cout << "The lowest of the result = " << lowest << endl;

system("pause");
return 0;
}

void determine_grade(double testScore)
{

cout << fixed << showpoint << setprecision(2);

if (testScore >= 90)
cout << "Grade A ";

else if (testScore >= 70)

cout << "Grade B ";

else if (testScore >= 60)

cout << "Grade C ";


else if (testScore >= 50)

cout << "Grade P ";

else if (testScore >= 0)
cout << "Grade U ";
return ;
}

double calc_average(double average[], double size)
{
int result;
int totalScore = 0;
for (int i = 0; i < size; i++)
{
totalScore += average[i];
}
result = totalScore / size;

return result;
}
double find_lowest(double value1[], int size1)
{
int minValue = 0;
for (int i = 0; i < size1; i++)
if (value1[i] < minValue)
{
minValue = value1[i];
}

return minValue;
}

double find_highest(double value[], int size)


{
int maxValue = 0;
for (int i = 0; i < size; i++)
{
if (value[i] > maxValue)
{
maxValue = value[i];
}

}

return maxValue;
}
Last edited on
int dg was unused and
determine_grade will always return true
Topic archived. No new replies allowed.