Question
My findLetterGrade function seems to be off (If I enter the first test key, 100, 90, 90 it returns F instead of an A), but
My findLetterGrade function seems to be off (If I enter the first test key, 100, 90, 90 it returns F instead of an A), but the conditions should be fine? Also, my output is not coming out how its supposed to is it because it needs to be set up within a loop?
// This program will input an undetermined number of student names // and a number of grades for each student. The number of grades is // given by the user. The grades are stored in an array. // Two functions are called for each student. // One function will give the numeric average of their grades. // The other function will give a letter grade to that average. // Grades are assigned on a 10 point spread. // 90-100 A 80- 89 B 70-79 C 60-69 D Below 60 F
#include
const int MAXGRADE = 25; // maximum number of grades per student const int MAXCHAR = 30; // maximum characters used in a name
typedef char StringType30[MAXCHAR + 1];// character array data type used for names // having 30 characters or less. typedef float GradeType[MAXGRADE]; // one dimensional integer array data type
float findGradeAvg(GradeType, int); // finds grade average by taking array of // grades and number of grades as parameters
char findLetterGrade(float); // finds letter grade from average given // to it as a parameter
int main()
{ StringType30 firstname, lastname; // two arrays of characters defined int numOfGrades; // holds the number of grades GradeType grades; // grades is defined as a one dimensional array float average; // holds the average of a student's grade char moreinput; // determines if there is more input
// Input the number of grades for each student
cout
cin >> numOfGrades;
while (numOfGrades > MAXGRADE || numOfGrades
cin >> numOfGrades;
}
// Input names and grades for each student
cout > moreinput;
while ( moreinput == 'y' || moreinput == 'Y')
{ cout > firstname; cout > lastname;
for (int count = 0; count
{
cout > grades[count];
// Fill in the input statement to place grade in the array
}
cout
cout > moreinput;
}
return 0; }
//*********************************************************************** // findGradeAvg // // task: This function finds the average of the // numbers stored in an array. // // data in: an array of integer numbers // data returned: the average of all numbers in the array // //***********************************************************************
float findGradeAvg(GradeType array, int numgrades)
{ double sum = 0.0;
for (int i = 0; i
return float (sum / numgrades); // Fill in the code for this function
}
//*********************************************************************** // findLetterGrade // // task: This function finds the letter grade for the number // passed to it by the calling function // // data in: a floating point number // data returned: the grade (based on a 10 point spread) of the number // passed to the function // //***********************************************************************
char findLetterGrade(float numgrade)
{ char letterGrade;
if (numgrade >= 90 && numgrade
else if (numgrade >= 80 && numgrade = 70 && numgrade = 60 && numgrade
return letterGrade;
}
Run the program with 3 grades per student using the sample data below. Mary Brown 100 90 90 George Smith 90 30 50 Dale Barnes 80 78 82 Sally Dolittle 70 65 80 Conrad Bailer 60 58 71 You should get the following results: Mary Brown has an average of 93.33 which gives the letter grade of A George Smith has an average of 56.67 which gives the letter grade of F Dale Barnes has an average of 80.00 which gives the letter grade of B Sally Dolittle has an average of 71.67 which gives the letter grade of C Conrad Bailer has an average of 63.00 which gives the letter grade of D
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started