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:

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
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
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education