This is homework that was graded last month, but I now have to reuse this as a basis for another program that I have to do. I need to know what I'm doing wrong on the math part to get it to work correctly for the next program.
This program seems to hold the information ok, but when it comes to the grade calculations I get random numbers. Do I need to initiate the variables or is something else going on that I'm not seeing?
Get rid of the loop that begins on line 61. The loop that begins on line 50 is already doing the job of this loop and it's boundary conditions are actually correct.
That's good, at least I'm at zero this way. What I've done so far is the following. It's still not giving me the correct answers mathematically, but I'm not getting the really screwy numbers like I was getting before.
#include <iostream> //basic, always here
#include <iomanip> //for setw
#include <string> //for string commands
#include <cstring> //for string commands
#include <cmath> //for math commands
usingnamespace std; //keeps the code shorter for the io commands
//Setting Constants these can be adjusted at a later date if necessary
constint MAXSTDS = 2; //Max Students in class
constint MAXGRDS = 3; //Max Grades per area (ex. 3 graded homework assignments)
constint MINGRDS = 1; //Min Grades per area (ex. 1 graded final test assignment)
constdouble HMWKPERC = 0.20; //Homework is 20 percent of grade
constdouble LABPERC = 0.25; //Lab is 25 percent of grade
constdouble TESTPERC = 0.30; //Tests are 30 percent of grade
constdouble FEXAMPERC = 0.25; //Final exam is 25 percent of grade
//Main Program Area
int main() //gotta start somewhere
{
//Setting Strings
string fname[MAXSTDS]; //First Name with a maximum that matches the number in MAXSTDS
string lname[MAXSTDS]; //Last Name with a maximum that matches the number in MAXSTDS
string stdID[MAXSTDS]; //Student ID number with a maximum that matches the number in MAXSTDS
//Setting other variables as needed
double hmwk[MAXSTDS][MAXGRDS] = {}; //Gets the grades for each student and holds them according to the student number
double lab[MAXSTDS][MAXGRDS] = {}; //Gets the grades for each student and holds them according to the student number
double test[MAXSTDS][MAXGRDS] = {}; //Gets the grades for each student and holds them according to the student number
double fexam[MAXSTDS][MINGRDS] = {}; //Gets the grades for each student and holds them according to the student number
double hmwkTotal[MAXSTDS] = {}; //Holds total homework grade for each student
double labTotal[MAXSTDS] = {}; //Holds total lab grade for each student
double testTotal[MAXSTDS] = {}; //Holds total test grade for each student
double fexamTotal[MAXSTDS] = {}; //Holds total final exam grade for each student
double hmwkAVG[MAXSTDS] = {}; //Holds average homework grade for each student
double labAVG[MAXSTDS] = {}; //Holds average lab grade for each student
double testAVG[MAXSTDS] = {}; //Holds average test grade for each student
double fexamAVG[MAXSTDS] = {}; //Holds average final exam grade for each student
double overall[MAXSTDS] = {}; //Holds overall grade for each student
double hmwkOVA[MAXSTDS] = {};//Holds hmwk percent total
double labOVA[MAXSTDS] = {};//Holds hmwk percent total
double testOVA[MAXSTDS] = {};//Holds hmwk percent total
double fexamOVA[MAXSTDS] = {};//Holds hmwk percent total
//First for loop getting student information
for (int j = 0; j < MAXSTDS; j++)
{
//system("CLS"); //Clears Screen for the second round
cout << "\n\nPlease enter the students first name: "; //Asking for first name
cin >> setw(35) >> fname[j]; //Holding first name info
cout << "\n\nPlease enter the students last name: "; //Asking for last name
cin >> setw(35) >> lname[j]; //Holding last name info
cout << "\n\nPlease enter the students ID number: "; //Asking for student ID number
cin >> setw(10) >> stdID[j]; //Holding ID number info
//Nested for loop gathering the homework grades
cout << "Please enter grades for " << fname[j] << " " << lname[j] << ": \n\n"; //Starts the grade gathering loops
for (int n = 0; n < MAXGRDS; n++)
{
//Gathering homework lesson grades for each student
cout << "Please enter the grade for homework lesson " << n + 1 << ": ";
cin >> hmwk[j][n]; //Storing the homework grades
hmwkTotal[j] += hmwk[j][n]; //adding homework grades to get a total per student
}
hmwkAVG[j] = hmwkTotal[j] / MAXGRDS; //Homework average
hmwkOVA[j] = hmwkAVG[j] * HMWKPERC; //calculating the homework overall percentage
for (int r = 0; r < MAXGRDS; r++)
{
//Gathering Lab lesson grades for each student
cout << "Please enter the grade for lab lesson " << r + 1 << ": ";
cin >> lab[j][r]; //Storing the lab grades
labTotal[j] += lab[j][r]; //adding lab grades to get a total per student
}
labAVG[j] = labTotal[j] / MAXGRDS; //Lab average
labOVA[j] = labAVG[j] * LABPERC; //calculating the lab overall percentage
for (int q = 0; q < MAXGRDS; q++)
{
//Gathering test grades for each student
cout << "Please enter the grade for test " << q + 1 << ": ";
cin >> test[j][q]; //Storing the test grades
testTotal[j] += test[j][q]; //adding test grades to get a total per student
}
testAVG[j] = testTotal[j] / MAXGRDS; //Test average
testOVA[j] = testAVG[j] * TESTPERC; //calculating the lab overall percentage
for (int d = 0; d < MINGRDS; d++)
{
//Gathering final test grades for each student
cout << "Please enter the final test grade: ";
cin >> fexam[j][d]; //Storing the final grade
fexamTotal[j] += fexam[j][d]; //adding final grade to get a total per student
}
fexamAVG[j] = testTotal[j] / MINGRDS; //Final Average
fexamOVA[j] = fexamAVG[j] * FEXAMPERC; //Calculating the lab overall percentage
overall[j] = hmwkOVA[j] + labOVA[j] + testOVA[j] + fexamOVA[j];
}
system("pause");
for (int r = 0; r < MAXSTDS; r++)
{
if (overall[r] >= 90 && overall[r] <= 100)
{
cout << fname[r] << " " << lname[r] << " " << setw(5) << fixed << setprecision(2) << overall[r] << setw(5) << "A" << endl;
}
elseif (overall[r] >= 80 && overall[r] <= 89)
{
cout << fname[r] << " " << lname[r] << " " << setw(5) << fixed << setprecision(2) << overall[r] << setw(5) << "B" << endl;
}
elseif (overall[r] >= 70 && overall[r] <= 79)
{
cout << fname[r] << " " << lname[r] << " " << setw(5) << fixed << setprecision(2) << overall[r] << setw(5) << "C" << endl;
}
elseif (overall[r] >= 60 && overall[r] <= 69)
{
cout << fname[r] << " " << lname[r] << " " << setw(5) << fixed << setprecision(2) << overall[r] << setw(5) << "D" << endl;
}
else
{
cout << fname[r] << " " << lname[r] << " " << setw(5) << fixed << setprecision(2) << overall[r] << setw(5) << "F" << endl;
}
system("pause");
}
return 0;
}