Hello, I am getting an error from my code, the program is not displaying the correct grades entered. Please help me find the solution, thank you. This is the code line I think is not working properly: cout << "The grade entered: " << *(characterPointer+i) << endl; Full code:

C++ for Engineers and Scientists
4th Edition
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Bronson, Gary J.
Chapter3: Assignment, Formatting, And Interactive Input
Section3.2: Formatting Numbers For Program Output
Problem 12E: (Civil eng.) Write a C++ program to calculate and display the maximum bending moment, M, of a beam...
icon
Related questions
Question

Hello, I am getting an error from my code, the program is not displaying the correct grades entered. Please help me find the solution, thank you. This is the code line I think is not working properly:

cout << "The grade entered: " << *(characterPointer+i) << endl;

Full code:

#include <iostream>
using namespace std;

char* gradeFinder(int*, int);
double gradeCalculate(int*, int);

int main(int argc, char** argv) {
int studentGrades[25];
int *myPointer = studentGrades;
char *characterPointer;
for (int i = 0; i < 25; i++)
{
cout << "Please enter the students' scores: ";
cin >> studentGrades[i];
while (studentGrades[i] < 0 || studentGrades[i] > 100)
{
cout << "Your entry was not between 0 - 100, please try again: ";
cin >> studentGrades[i];
}
}
characterPointer = gradeFinder(myPointer, 25);
for (int i = 0; i < 25; i++)
{
cout << "The grade entered: " << *(characterPointer+i) << endl;
}
cout << "The average of these grades is: " << gradeCalculate(myPointer, 25);

return 0;
}

char* gradeFinder(int* findGrade, int gradeNumber)
{
char letterGrades[gradeNumber];
char *letterPointer = letterGrades;
for (int i = 0; i < gradeNumber; i++)
{
if (*(findGrade+i) >= 90 && *(findGrade+i) <= 100)
{
letterGrades[i] = 'A';
}
else if (*(findGrade+i) >= 80 && *(findGrade+i) < 90)
{
letterGrades[i] = 'B';
}
else if (*(findGrade+i) >= 70 && *(findGrade+i) < 80)
{
letterGrades[i] = 'C';
}
else if (*(findGrade+i) >= 60 && *(findGrade+i) < 70)
{
letterGrades[i] = 'D';
}
else
{
letterGrades[i] = 'F';
}
}
return letterPointer;
}

double gradeCalculate(int* findGrade, int numberOfGrades)
{
int highest;
int lowest;
double average = 0;
for (int i = 0; i < numberOfGrades; i++)
{
average += *(findGrade+i);
if (*(findGrade+i) > highest) highest = *(findGrade+i);
if (*(findGrade+i) < lowest) lowest = *(findGrade+i);
}
average -= (highest + lowest);
average = average/numberOfGrades;
return average;
}

 

Thanks again.

Expert Solution
steps

Step by step

Solved in 2 steps

Blurred answer
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ for Engineers and Scientists
C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr
Microsoft Visual C#
Microsoft Visual C#
Computer Science
ISBN:
9781337102100
Author:
Joyce, Farrell.
Publisher:
Cengage Learning,