Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Hello, I am trying to pass an array, that contains user input up to 10 scores or

ID: 3640570 • Letter: H

Question

Hello,
I am trying to pass an array, that contains user input up to 10 scores or exiting by entering -1, back to the main function. Then figuring out the highest score, lowest score, average, and letter grade with this array. My first problem is how do I transfer the data back that is created in an array to the main function in order to find my stats? If anyone can help me with this I'm sure if there are any other errors I can figure them out myself. Thanks!
This is what I currently have.

fyi: I bolded the areas that are the most important to fix.

//Purpose: Have user input upto 10 grades and make a table that showcases grade, average, high score, low score and how many exams were entered.

#include <iostream>
#include <iomanip>
using namespace std;

//functions

int PromptForExamScore (void);
void DisplayOutput (int[], int);
char ExamGrade (int);
int AverageExamGrade (int[], int);
int HighestExamGrade (int[], int);
int LowestExamGrade (int[], int);
void ClearScreen (void);

//variables
const int DATA = 10;

int main()

{ int count, Input;
int grades[DATA];
cout << " Please enter upto 10 grades.";
cout << " If you have less than 10 grades enter -1 to exit." << endl;

grades [DATA] = PromptForExamScore();



HighestExamGrade (grades, DATA);
LowestExamGrade (grades, DATA);
ClearScreen();

AverageExamGrade (grades, DATA);

// just put to test and make sure it was working but it isn't.
for (count = 0; count < DATA; count++)
cout << "grades [" <<count <<"] is" << grades[count] << endl;


return 0;

}

int PromptForExamScore (void)
{ int input[DATA], count;
const int NEGOUT = -1;
for (count = 0; count < DATA; count++)
{
cin >> input[count];

if ( input[count] == NEGOUT)
break;

}

return input[count];
}


void DisplayOutput (int vals[], int x)
{
int y;
int low, high, avg;
avg=AverageExamGrade (vals, x);
low= LowestExamGrade (vals, x);
high=HighestExamGrade (vals, x);

cout << "-----------------------------------------------" << endl;
cout << "| EXAM | SCORE | GRADE |" << endl;
cout << "| HIGH |" << high << ExamGrade (high) << "|" << endl;
cout << " |AVG |" << avg << ExamGrade (avg) << "|" << endl;
cout << "| LOW |" << "|" << low <<"|" << ExamGrade (low) <<"|" << endl;
for ( y=0; y < DATA; y++)
cout <<"|" << y <<"|" << vals[y] <<"|" << ExamGrade(vals[y])<<"|" << endl;
cout << "-----------------------------------------------" << endl;


return;
}

char ExamGrade (int grade)
{ char lettergrade;
if ( grade >= 90 && grade <= 100)
cout << "A";
else if ( grade >= 80 && grade <= 89)
cout <<"B";
else if( grade >= 70 && grade <= 79)
cout << "C";
else if( grade >= 60 && grade <= 69)
cout << "D";
else
cout << "F";
return lettergrade;
}

int AverageExamGrade (int examgrades[], int Average)
{ int counter, average = examgrades[0];
for (counter = 0; counter < Average; counter++)
average = examgrades[counter]/counter;
return average;
}

int HighestExamGrade (int scores[], int Highest)
{
int highest = scores[0], counter;
for (counter = 0; counter < Highest; counter++)
if (highest > scores[counter]) highest = scores[counter];

return highest;
}


int LowestExamGrade (int grades[], int Lowest)
{
int lowest = grades[0], counter;
for (counter = 0; counter < Lowest; counter++)
if (lowest < grades[counter]) Lowest = grades[counter];
return lowest;
}


void ClearScreen (void)
{
cout << "";
return;
}

Explanation / Answer

It would probably be easier to use pointers

int * PromptForExamScore (void){
int input[DATA], count;
const int NEGOUT = -1;
for (count = 0; count < DATA; count++) {
cin >> input[count];
if ( input[count] == NEGOUT)
break;
}
return input;
}

You would also have to declare an int * and use that as the variable that gets the return from PromptForExamScore() (You can probably just change grades to an int *). I'm not sure on this, but to get the actual data that the variable is pointing to, you would do *grades.

Hope this helps.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote