Good Morning,
I'm having some problems with my code. This program is to have at least 5 functions .
1.)Ingrades: a two dimensional array that stores student ID, grades and times absent.
2.)Score. Calculates scores for all course work (two partial tests 15% each , two quizzes 10 %each, 1 project 20%1 final 30%.
3.standev - calculates the standard deviation of each course work
4.Modif - lets user modify any score or absent total
5.ViewGradesl: outputs all the grades for each student ID entered

My problem so far, my code runs, but I'm having major problems with the following functions:

1.)Ingrade: my problem here is that I'm not really sure in which index I'm storing the Absence Count.
2.) Score : I made it really simple assuming all scores where the same. But I'm having problems trying to give a 15% value to tests and 10% ten to quizzes and so on.. so in the end I can compute the final grade correctly. And also I have problems when running the subtraction of -1% if student is absent it is deducted a 1% of the final grade. and if the student is absent more than than ten times it is an F. I can put all 100 and 1 absent and the program sometimes gives out an F.

3.)standev: This works ok (I think )

4.) Modif: welll , where to start with this one?. It is supposed to modify the original array with new grades for each student ID and then recompute using function score. but any sort of value I enter I don't know where I'm sending it. I thought I was sending it to the original array but apparently I'm not

5.) ViewGrades works ok, displaying each student id and all grades , but I wish to modify it to actually display some sort of table.


I would gladly appreciate any ideas or help I'm exhausted with this project

#include<iostream> //Librerias
#include<cmath> //Librerias
using namespace std;

/* Function prototypes */

void Ingrades (double[][10], int); // Function that lets user input student ID, two partial exams one final, two quizzes and one project and studentCount of twenty classes
void Score (double[][10], int);//Score and mean calculations
void Standev (double[][10], int); //Function that calculates standard deviation
void Modif (double [][10], int);  //Function that lets user change any student grades for any test and studentCount 
void ViewGrades (double[][10], int); //Function that displays the Score of each test for each student and outputs the final grade.
int main ()
{
	const int studentCount=15, studentRecords=10;//We initialize arrays to dimensions studentCount is twenty max number of classes and studentRecords fifteen max number of students.
	int option, i, studentID;

/* MultiDemensional Array : first dimension is fifteen that represents the student count 
Second dimension is ten that represents the student records to be modified
zero row represents students ID
rows one to seven represents student grades  composed of : two partial tests, two quizzes, one project and one final
row eight represent ABSENCES
row nine represents  final grade
*/

	double gradeBook[studentCount][studentRecords];
	                      
	     
	
	cout<<"	\t \t Student GradeBook  "<<endl;
	
	cout<<"Enter the amount of the students (1 to 15): ";
	cin>>studentID; // asks for total number of students
	while(studentID<1 ||studentID>15)//student count is 15
	{
		cout<<"The student quantity should be from 1 to 15. \nPlease Re-Enter: ";
		cin>>studentID;
	}
	for (i=0; i<studentID; i++)//Array initialized to 0 
	{
		gradeBook[i][0]=0;
		gradeBook[i][10]=-1;
	}
	do // do loop for menu
	{
		option=0;
		/* Options Menu*/
		cout<<"1. Enter the student grades (2 partial exams, 2 quizzes, 1 proyect 1 final ) and studentRecords (20 total attendance)"<<endl;
		cout<<"2. Compute each student's mean score and final grade"<<endl;
		cout<<"3. Compute the variance and the standard deviation for each exam and final score";
		cout<<"4. Modify Grades"<<endl;
		cout<<"5. List the Grades"<<endl;
		cout<<"6. Exit"<<endl;
		cout<<"Please choose an option: ";
		cin>>option;
		cout<<endl<<endl;
		while(option<1||option>6)// validation loop
		{
			cout<<"ERROR INVALID SELECTION"<<endl;
			cout<<"Please, re-enter one of the earlier options: ";
			cin>>option;
		}
		switch (option)// Selection menu to populate the arrays
		{
		case 1:
			if(gradeBook[0][0]!=0)// validation statement
			{
				cout<<"This process can't be done again."<<endl;
				cout<<"Select options 2-6."<<endl<<endl;
			}
			else
			Ingrades(gradeBook, studentID);//call for Ingrades function with gradebook and studentID 
			break;
		case 2:
			Score(gradeBook, studentID);//calls for function Score that calculates scores for gradebook and student id dimensions
			break;
		case 3:
			Standev(gradeBook, studentID);// calls for function Standdev for a all tests 
			break;
		case 4:
			Modif(gradeBook, studentID);//calls for function Modif that lets user modify any student record including test and Attendance
			break;
		case 5:
			ViewGrades(gradeBook, studentID);//View Grades for entire class or students entered
			break;
		case 6:
			cout<<"GOOD BYE "<<endl<<endl;
			break;
		}
		// All functions called and they send parameters to each function definition. 
	}while(option>=1&&option<=5);
	return 0;
}
//end main

/* Function DEFINITIONS */


void Ingrades (double gradeBook[][10],int studentCount)//
{
	// i represents students count and j represents student data: grades, ID and absent count
	int i, j;
	for(i=0; i<studentCount; i++)//studentCout initialized to 0 
	{
		for(j=0; j<1; j++)// For repetition cycle that asks for students ID 
		{
			cout<<"Enter the student's ID number: ";
			cin>>gradeBook[i][j];
			while(gradeBook[i][j]<=0)//Student id cannot be <= 0
			{
				cout<<"Invalid ID Number. Re-enter again....: ";
				cin>>gradeBook[i][j];
			}
		}
		cout<<"Enter in the following order: \n test1 = 1, test2= 2, quiz1= 3, quiz2= 4, project1= 5 FINAL =6"<<endl;

		for(j=1; j<7; j++)//
		{
			cout<<"Enter the grades  "<<j<<": ";
			cin>>gradeBook[i][j];
			while(gradeBook[i][j]>100||gradeBook[i][j]<0)// gradeBook validated that grades cannot be lower than zero and greater than a hundred 
			{
				cout<<"INVALID GRADES"<<endl;
				cout<<"Please Re-Enter: ";
				cin>>gradeBook[i][j];
			}
		}
		for(j=8; j<9; j++)//Counts for Absences
		{
			cout<<"Enter the student's number of absences (Total of clases: 20): ";
			cin>>gradeBook[i][j];
			while(gradeBook[i][j]<0||gradeBook[i][j]>20)// while validation Class total is twenty , Absences cannot be more than the total of classes
			{
				cout<<"**The number of absences exceed the number of classes**"<<endl;
				cout<<"Re-enter: ";
				cin>>gradeBook[i][j];
			}
			cout<<endl<<endl;
		}
	}
}
void Score (double gradeBook[][10],int studentCount)//Function that calculates students grade
{
	int i, j;
	for (i=0; i<studentCount; i++) // To call for this function you have to select option 1 in main that populates student Records
		if (gradeBook[i][0]==0)
		{
			cout<<"***No students were registered***.";
			cout<<"Select Option 1."<<endl;
			break;
		}	
		else // IF there's a valid ID entered then function is executed	
		{
	
			for (i=0; i<studentCount; i++)
			{
				if(gradeBook[i][8]>=10)  //row eight is where ABSENCES are stored
					gradeBook[i][10]=0;//If there are more than ten ABSENCES then GRADE is F
				else
				{
					for(i=0; i<studentCount; i++)
					{
						for (j=0; j<gradeBook[i][8]; j++)
							gradeBook[i][10]-=1.0;//Rests 1.0% out of the final grade for each ABSENCE
						if(gradeBook[i][10]<0)
							gradeBook[i][10]=0;//IF Final grade is negative then score is F. 
					}
				}
			}
		}
		cout<<"*************************************"<<endl;
		cout<<"* All the calculations have been done *"<<endl;//
		cout<<"*************************************"<<endl<<endl<<endl<<endl;
}
void Standev (double gradeBook[][10], int studentCount)//Function that calculates Standard Deviation
{
	int i, j, a, w;
	double sum, average, rum, stdVariance, std_deviation;
	for(a=0; a<studentCount; a++)
		{ // Validation for initial values of the array, GRADES must be entered for this function to work 
		if (gradeBook[0][0]==0)
		{
			cout<<"No Grades were registered."<<endl;
			cout<<"Select Option 1."<<endl;
			break;
		}
		else if(gradeBook[0][10]==-1)
		{
			cout<<"No calculations have been made nor grades were registrered."<<endl;
			cout<<"Select Option 2."<<endl<<endl<<endl;
			break;
		}
		else
		{
			do// Repeats Standard Deviation MENU
			{
				cout<<"Press 1 to see the variance and standard deviation of the first exam."<<endl;
				cout<<"Press 2 to see the variance and standard deviation of the second exam."<<endl;
				cout<<"Press 3 to see the variance and standard deviation of the first quiz"<<endl;
				cout<<"Press 4 to see the variance and standard deviation of the second quiz"<<endl;
				cout<<"Press 5 to see the variance and standard deviation of the project 1"<<endl;
				cout<<"Press 6 to see the variance and standard deviation of the final exam."<<endl;
				cout<<"Press 7 to see the variance and standard deviation of the final score."<<endl;
				cout<<"Press 8 to exit."<<endl;
				sum=0;
				rum=0;
				average;
				stdVariance=0;
				std_deviation=0;
				w=0; // Second menu Selection 
				cin>>w;
				while(w<1||w>8)//Validates MENU
				{
					cout<<"***Error***===Please Re-Enter.";
					cin>>w;
				}
				switch (w)
				{      // Each CASE Computes the standard deviation of all grades for each EXAM 
				case 1:
					for(i=0; i<studentCount; i++)					
						for(j=1; j<2; j++)
							sum+=gradeBook[i][j];//Sums all of the GRADES of Examn ONE.
					average=sum/studentCount;//Divide the sum of the GRADES entered by the total of students entered (Average)
					for(i=0; i<studentCount; i++)					
						for(j=1; j<2; j++)
							rum+=(gradeBook[i][j]-average)*(gradeBook[i][j]-average);//Stores the sum in a variable
					stdVariance=rum/(studentCount-1);//divides the calculation by the total number of grades minus one to get curve
					std_deviation=sqrt(stdVariance); // sqrt of variation, using sqrt from cmath library gives out the Std deviation
					cout<<"Variance for the first test is: "<<stdVariance<<endl;
					cout<<"Standard deviation for the first test is is: "<<std_deviation<<endl<<endl;
					break;
				case 2: //Calculates standard deviation for the second test
					for(i=0; i<studentCount; i++)					
						for(j=2; j<3; j++)
							sum+=gradeBook[i][j];
					average=sum/studentCount;
					for(i=0; i<studentCount; i++)					
						for(j=2; j<3; j++)
							rum+=(gradeBook[i][j]-average)*(gradeBook[i][j]-average);
					stdVariance=rum/(studentCount-1);
					std_deviation=sqrt(stdVariance);
					cout<<"Variance for the second test is: "<<stdVariance<<endl;
					cout<<"Standard deviation for the second test is is: "<<std_deviation<<endl<<endl;
					break;		
				case 3: //Calculates standard deviation for quiz one
						for(i=0; i<studentCount; i++)					
						for(j=3; j<4; j++)
							sum+=gradeBook[i][j];
					average=sum/studentCount;
					for(i=0; i<studentCount; i++)					
						for(j=3; j<4; j++)
							rum+=(gradeBook[i][j]-average)*(gradeBook[i][j]-average);
					stdVariance=rum/(studentCount-1);
					std_deviation=sqrt(stdVariance);
					cout<<"Variance for the first quiz is: "<<stdVariance<<endl;
					cout<<"Standard deviation for the first quiz is: "<<std_deviation<<endl<<endl;
					break;
				case 4://Calculates standard deviation for quiz two
					for(i=0; i<studentCount; i++)					
						for(j=4; j<5; j++)
							sum+=gradeBook[i][j];
					average=sum/studentCount;
					for(i=0; i<studentCount; i++)					
						for(j=4; j<5; j++)
							rum+=(gradeBook[i][j]-average)*(gradeBook[i][j]-average);
					stdVariance=rum/(studentCount-1);
					std_deviation=sqrt(stdVariance);
					cout<<"Variance for the second quiz is: "<<stdVariance<<endl;
					cout<<"Standard deviation for the second quiz is: "<<std_deviation<<endl<<endl;
					break;
				case 5://Calculates standard deviation for project
					for(i=0; i<studentCount; i++)					
						for(j=5; j<6; j++)
							sum+=gradeBook[i][j];
					average=sum/studentCount;
					for(i=0; i<studentCount; i++)					
						for(j=5; j<6; j++)
							rum+=(gradeBook[i][j]-average)*(gradeBook[i][j]-average);
					stdVariance=rum/(studentCount-1);
					std_deviation=sqrt(stdVariance);
					cout<<"Variance for the project is: "<<stdVariance<<endl;
					cout<<"Standard deviation for the project is : "<<std_deviation<<endl<<endl;
					break;

				case 6: //calculates standard deviation for FINAL TEST
					for (i=0; i<studentCount; i++)
						for (j=7; j<8; j++)
							sum+=gradeBook[i][j];
					average=sum/studentCount;
					for(i=0; i<studentCount; i++)
						for(j=7; j<8; i++)
							rum+=(gradeBook[i][j]-average)*(gradeBook[i][j]-average);
					stdVariance=rum/(studentCount - 1);
					std_deviation=sqrt (stdVariance);
					cout<<"Variance for the final exam is: "<<stdVariance<<endl;
					cout<<"Standard deviation for the final exam is: "<<std_deviation<<endl<<endl;
					break;
				case 7: // calculates the standard deviation of the FINAL GRADE
					for(i=0; i<studentCount; i++)					
						for(j=8; j<9; j++)
							sum+=gradeBook[i][j];//Sums all of the GRADES of Final Grade.
					average=sum/studentCount;//Divide the sum of the GRADES entered by the total of students entered (Average)
					for(i=0; i<studentCount; i++)					
						for(j=8; j<9; j++)
							rum+=(gradeBook[i][j]-average)*(gradeBook[i][j]-average);//Stores the sum in a variable
					stdVariance=rum/(studentCount-1);//divides the calculation by the total number of grades minus one to get curve
					std_deviation=sqrt(stdVariance); // sqrt of variation, using sqrt from cmath library gives out the Std deviation
					cout<<"Variance for the FINAL GRADE is: "<<stdVariance<<endl;
					cout<<"Standard deviation for the FINAL GRADE is: "<<std_deviation<<endl<<endl;
					break;


				case 8:// Menu Exits
				break;
				}
			}while(w>=1&&w<=8);
		}
		if(w==8)// if hits 8 goes back to previous menu
			break;
	}
}






void Modif (double gradeBook[][10], int studentCount)//Function that permits the change student grades and Attendance
{
	int i, k, ghj;
	if (gradeBook[0][0]==0)//array initialized
	{
		cout<<"No student were registered"<<endl;
		cout<<"Please, refer to option 1."<<endl;
	}
	else
	{
		for(i=0; i<studentCount; i++)
		{
			cout<<"You can Modif the student's grades in the order you entered them, or skip to the other student.\n";
			cout<<"Student # " <<i+1<<" ( ID# "<<gradeBook[i][0]<<" )" <<endl<<endl;
			do
			{
				cout<<"Enter 1 to Modify the grade of the first test."<<endl;
				cout<<"Enter 2 to Modify the grade of the second test."<<endl;
				cout<<"Enter 3 to Modify the grade of the first quiz"<<endl;
				cout<<"Enter 4 to Modify the grade of the second quiz."<<endl;
				cout<<"Enter 5 to Modify the grade of the project"<<endl;
				cout<<"Enter 6 to Modify the grade of the FINAL TEST"<<endl;
				cout<<"Enter 7 to Modify the absences."<<endl;
				cout<<"Enter 8 to skip this student, or to exit."<<endl<<endl;
				k=0;
				ghj=0;
				cin>>k;
				while(k<1||k>8)
				{
					cout<<"***Invalid Option***\n Please Re-Enter: ";
					cin>>k;
				}
				switch (k)
				{
					case 1: //each case validates for wrong values and modifies existing values in gradeBook
						cout<<"Enter the new score for first test: ";
						cin>>ghj;
						while(ghj>100||ghj<0)
						{
							cout<<"***Invalid Grade Value*** Re-Enter: ";
							cin>>ghj;
						}
						gradeBook[i][1]=ghj;
						cout<<"New value for grade of the first test is: "<<gradeBook[i][1]<<"%"<<endl<<endl;
						break;
					case 2:
						cout<<"Enter the new score for second test: ";
						cin>>ghj;
						while(ghj>100||ghj<0)
						{
							cout<<"***Invalid Grade Value***\n Please Re-Enter: ";
							cin>>ghj;
						}
						gradeBook[i][2]=ghj;
						cout<<"New value for grade of the second test is: "<<gradeBook[i][2]<<"%"<<endl<<endl;
						break;
					case 3:
						cout<<"Enter the new score for the first quiz: ";
						cin>>ghj;
						while(ghj>100||ghj<0)
						{
							cout<<"***Invalid grade value***\nPlease Re-Enter: ";
							cin>>ghj;
						}
						gradeBook[i][3]=ghj;
						cout<<"New value for grade of the first quiz is: "<<gradeBook[i][3]<<"%"<<endl<<endl;
						break;
					case 4:
						cout<<"Enter the new score for the second quiz: ";
						cin>>ghj;
						while(ghj>100||ghj<0)
						{
							cout<<"***Invalid Grade Value***\nPlease Re-Enter: ";
							cin>>ghj;
						}
						gradeBook[i][4]=ghj;
						cout<<"New value for grade of the second quiz is: "<<gradeBook[i][4]<<"%"<<endl<<endl;
						break;

					case 5:
							cout<<"Enter the new score for the project: ";
						cin>>ghj;
						while(ghj>100||ghj<0)
						{
							cout<<"***Invalid Grade Value***\nPlease Re-Enter: ";
							cin>>ghj;
						}
						gradeBook[i][5]=ghj;
						cout<<"New value for grade of the project is: "<<gradeBook[i][4]<<"%"<<endl<<endl;
						break;

					case 6:
						cout<<"Enter the new score for the FINAL TEST ";
						cin>>ghj;
						while(ghj>100||ghj<0)
						{
							cout<<"***Invalid Grade Value***\nPlease Re-Enter: ";
							cin>>ghj;
						}
						gradeBook[i][6]=ghj;
						cout<<"New value for grade of the FINAL TEST is: "<<gradeBook[i][4]<<"%"<<endl<<endl;
						break;


					case 7:
						cout<<"Enter the new number of absences: ";
						cin>>ghj;
						while(ghj>20||ghj<0)//Validation of attendance only twenty classes
						{
							cout<<"Remember, there are only 20 classes and the value cannot be negative...."<<endl;
							cout<<"Please re-enter: ";
							cin>>ghj;
						}
						gradeBook[i][7]=ghj;
						cout<<"New value for absences is: "<<gradeBook[i][7]<<endl<<endl;
						break;
				}
				if(k==8)
				{
					break;
				}
			}while(k>=1&&k<=7);
		}
		cout<<"Choose option 2 to calculate the new grades or absences..."<<endl<<endl;
		//Then user needs to perform option two in main menu to calculate the new grades based on new data entered
	}
}





void ViewGrades (double gradeBook[][10], int studentCount)//This function show the wholes grade for each student
{
int i, j, k; 
	double note=0;
	char x;
	if (gradeBook[0][0]==0)
		cout<<"No ID numbers were entered. Select to option 1."<<endl<<endl;
	else if(gradeBook[0][10]==-1)
		cout<<"No calculations have been made. Select option 2."<<endl<<endl;
	else
	{
		for(i=0; i<studentCount; i++)//Student count
		{
			for(j=0; j<1; j++)//First row is for ID
			{
				cout<<"The scores for student's (With ID #: "<<gradeBook[i][j]<<")tests are:\n";
				for(k=1; k<7; k++)//GRADES are positions from 1, 2, 3, 4,5, 6,7 of array
					cout<<gradeBook[i][k]<<"%"<<endl;
				cout<<"With ";
				for(k=8; k<9; k++)//Remember position 8 of the array is for the ATTENDANCE
					cout<<gradeBook[i][k];
				cout<<" absences to class."<<endl;
				cout<<"Final grade is ";
				if (gradeBook[i][10]<=100&&gradeBook[i][10]>=90)
					x='A';// if final avarage is between 90 & 100  it's an A
				else if (gradeBook[i][10]<=89&&gradeBook[i][10]>=80)
					x='B';// if final avarage is between 80 & 89 it's a B
				else if (gradeBook[i][10]<=79&&gradeBook[i][10]>=70)
					x='C';// if final avarage is between 70 & 79 it's a C
				else if (gradeBook[i][10]<=69&&gradeBook[i][10]>=60)
					x='D';// if final avarage is between 60 & 69 it's a B
				else
					x='F';// If its lower than 59 then it's an F
				cout<<x<<"(";
				for(k=7; k<8; k++)
					cout<<gradeBook[i][10];
				cout<<"%)."<<endl<<endl; //prints out final grade letter and percent
			}
		}
	}
}

Right off the bat, I see a few problems just in the very beginning:

#include<iostream> //Librerias
#include<cmath> //Librerias
using namespace std;

/* Function prototypes */

void Ingrades (double[][10], int); // Function that lets user input student ID, two partial exams one final, two quizzes and one project and studentCount of twenty classes
void Score (double[][10], int);//Score and mean calculations
void Standev (double[][10], int); //Function that calculates standard deviation
void Modif (double [][10], int);  //Function that lets user change any student grades for any test and studentCount 
void ViewGrades (double[][10], int); //Function that displays the Score of each test for each student and outputs the final grade.
int main ()
{
	const int studentCount=15, studentRecords=10;//We initialize arrays to dimensions studentCount is twenty max number of classes and studentRecords fifteen max number of students.
	int option, i, studentID;

/* MultiDemensional Array : first dimension is fifteen that represents the student count 
Second dimension is ten that represents the student records to be modified
zero row represents students ID
rows one to seven represents student grades  composed of : two partial tests, two quizzes, one project and one final
row eight represent ABSENCES
row nine represents  final grade
*/

	double gradeBook[studentCount][studentRecords];
	                      
	     
	
	cout<<"	\t \t Student GradeBook  "<<endl;
	
	cout<<"Enter the amount of the students (1 to 15): ";
	cin>>studentID; // asks for total number of students
	while(studentID<1 ||studentID>15)//student count is 15
	{
		cout<<"The student quantity should be from 1 to 15. \nPlease Re-Enter: ";
		cin>>studentID;
	}
	for (i=0; i<studentID; i++)//Array initialized to 0 
	{
		gradeBook[i][0]=0;
		gradeBook[i][10]=-1;
	}

Line 23 - you have six scores. Why do you have rows 1 through 7 to store them instead of rows 1 - 6?

Line 44 - Valid indexes for the second index are 0 to 9. Using index 10 may or may not be a seg fault, but you shouldn't do that.


As for your problems/questions, you say you are storing absences in index 8 above and that appears to be the case in lines 130 - 141 in your code. What do you mean when you say you aren't sure where you're storing it?

This is a lot of code to go through. Please give us more precise questions to work off of. "I'm having problems" is a bit vague. Test the program, see if it works, and if it doesn't, tell us the exact input you used, the exact output you got, and what the output should have been.

Edited 7 Years Ago by VernonDozier: n/a

Comments
helpful

my main problem is that I really don't grasp how to use multi-dimensional arrays that well, I'm having problem specifically in the part of the Score function and then in the ViewGrades function for example:

I entered grades for 3 students but only two calculations come out ok then third one automatically gives me an F to that student id and if I enter 5 student's records the last student ID will become 0% F

The scores for student's (With ID #: 1)tests are:
100%
100%
100%
100%
100%
100%
With 5 absences to class.
Final grade is A(95%).

The scores for student's (With ID #: 95)tests are:
100%
100%
100%
100%
100%
100%
With 10 absences to class.
Final grade is F(0%).

The scores for student's (With ID #: 0)tests are:
100%
100%
100%
100%
100%
100%
With 0 absences to class.
Final grade is F(0%).

This function asks to input all six grades, but given that all grades have the same value.

I'm out of ideas how to ask and store in an array given that each grade has a different value. How would I store for example that test 1 , test 2 are each 20% and quizzes 10% and project 20% and final 30%?

void Ingrades (double gradeBook[][10],int studentCount)//
{
	// i represents students count and j represents student data: grades, ID and absent count
	int i, j;
	for(i=0; i<studentCount; i++)//studentCout initialized to 0 
	{
		for(j=0; j<1; j++)// For repetition cycle that asks for students ID 
		{
			cout<<"Enter the student's ID number: ";
			cin>>gradeBook[i][j];
			while(gradeBook[i][j]<=0)//Student id cannot be <= 0
			{
				cout<<"Invalid ID Number. Re-enter again....: ";
				cin>>gradeBook[i][j];
			}
		}
		cout<<"Enter in the following order: \n test1 = 1, test2= 2, quiz1= 3, quiz2= 4, project1= 5 FINAL =6"<<endl;

		for(j=1; j<7; j++)//
		{
			cout<<"Enter the grades  "<<j<<": ";
			cin>>gradeBook[i][j];
			while(gradeBook[i][j]>100||gradeBook[i][j]<0)// gradeBook validated that grades cannot be lower than zero and greater than a hundred 
			{
				cout<<"INVALID GRADES"<<endl;
				cout<<"Please Re-Enter: ";
				cin>>gradeBook[i][j];
			}
		}
		for(j=8; j<9; j++)//Counts for Absences
		{
			cout<<"Enter the student's number of absences (Total of clases: 20): ";
			cin>>gradeBook[i][j];
			while(gradeBook[i][j]<0||gradeBook[i][j]>20)// while validation Class total is twenty , Absences cannot be more than the total of classes
			{
				cout<<"**The number of absences exceed the number of classes**"<<endl;
				cout<<"Re-enter: ";
				cin>>gradeBook[i][j];
			}
			cout<<endl<<endl;
		}
	}
}

My first thought is : use a StudentGrades struct and an array of such structures; it will make the whole thing readable at least :)

But let's see what should happen here in the "Ingrade" function ( wierd name by the way ).
You say: "// Function that lets user input student ID, two partial exams one final, two quizzes and one project and studentCount of twenty classes"

If i get this right, you want the user to give you "n" students, their grades & their absences ? And you want to save this info in the 2D array ?

You should do this in a single go like this:

// ! All this assumes that you have an array big enough to hold "n" arrays of 8 int positions !
    char * gradeType[6] = {"test1", "test2", "quiz1", "quiz2", "project", "Final"};
    for(int i = 0; i < studentCount; i++)
    {
        cout << "Enter the student's ID number: ";
        cin >> gradeBook[i][0];

        for(int j = 1; j < 7/*number of grades + 1 because at position [0] you stored the ID*/; j++)
        {
            cout << "Enter grade for " << gradeType[j-1] << ": ";
            cin >> gradeBook[i][j];
        }

        cout << "Enter the student's absence count: ";
        cin >> gradeBook[i][7];
    }

You must fix that bad index problem for this program to work. You can't use 10 as the second index. Valid indexes are 0 through 9. If you use 10, even if it compiles and runs, it almost certainly is overwriting information that you don't want it to overwrite, which makes your program unpredictable.

Run this program to get a sense of what I mean:

#include <iostream>
using namespace std; 

int main()
{
    int a[15][10];
    a[1][0] = 6;
    a[0][10] = 9;
    
    cout << a[1][0] << endl;
    return 0;
}

Result? You get a display of 9, which means the 6 was written over. Why? Because I used an invalid index and therefore a[1][0] and a[0][10] both point to the same address.

So you have two choices:

  1. Change your array declaration to double gradeBook[studentCount][studentRecords+1] so that legal second indexes are 0 through 10, not 0 through 9.
  2. Go through your code and make sure nothing is stored where the second index is 10.

The first solution is much quicker. Try it. Perhaps the problem will go away.

Note that if you elect to use my first option in the prior post, you must change declarations like this:

void Ingrades (double gradeBook[][10],int studentCount)

to

void Ingrades (double gradeBook[][11],int studentCount)

so they match the original array declaration. Otherwise all offset calculations will be incorrect.

Ok, I've been doing some modifications on my code and everything but the modif function works ok. The modif function although it runs and compiles. It actually does nothing to the original array thus I cannot recalculate scores based on the new scores entered. any help? How would I send the values asked from the modif function to the original array stored by the Ingrades function ? o.O .

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

void Ingrades (double[][9], int);
void Score (double[][9], int);
void Standev (double[][9], int);
void Modif (double [][9], int); 
void ViewGrades (double[][9], int);
int main ()
{
	const int Students=15, records=9;
	int option, i, student;

double gradebook[Students][records];

cout<<"**********Students' grade book***********\n";
cout<<"Enter the amount of students";
cin>>student;
while(student<1||student>15)
{
	cout<<"Student must be 1 to 15,please re-enter";
	cin>>student;
}
for (i=0; i<student;i++)
{
	gradebook[i][0]=0;
	gradebook[i][8]=-1;
}
do
{
	option=0;
	cout<<"1.Enter the students grade, (two partial exam and one final, quizes and project) and attendence to class"<<endl;
	cout<<"2.Compute each student score and final grade"<<endl;
	cout<<"3.Compute the variance and standard deviation of the exams and final score"<<endl;
	cout<<"4.Modify grade"<<endl;
	cout<<"5.List of students' grade"<<endl;
	cout<<"6.FINISH"<<endl;
	cout<<"Choose an option";
	cin>>option;
	cout<<endl;
while(option<1||option>6)//un while para validar
		{
			cout<<"*****ERROR,ERROR*****"<<endl;
			cout<<"Please, re-enter the option";
			cin>>option;
		}
switch (option)//Se empiesan a editar los cases
		{
		case 1:
			if(gradebook[0][0]!=0)//Obviamente ya un veaz hayas registrado estudiantes no podras hacerlo de nuevo por eso creamos este IF
			{
				cout<<"This process can't be done again."<<endl;
				cout<<"Select options 2-6."<<endl<<endl;
			}
			else
				Ingrades(gradebook, student);
			break;
		case 2:
			Score(gradebook, student);
			break;
		case 3:
			Standev(gradebook, student);
			break;
		case 4:
			Modif(gradebook, student);
		case 5:
			ViewGrades(gradebook, student);
			break;
		case 6:
			cout<<"~~~~~~~~~~THANKS FOR USING STUDENTS' GRADE BOOK~~~~~~~~~~"<<endl<<endl;
			break;
}
	}while(option>=1&&option<=5);
	return 0;
	
}
	void Ingrades (double gradebook[][9],int Students)
	{
		int i, j;
			for(i=0;i<Students;i++)
			{
				for(j=0;j<1;j++)
				{
		cout<<"Enter students' ID#";
		cin>>gradebook[i][j];
while(gradebook[i][j]<=0)
			{
				cout<<"***Invalid ID Number***. Re-enter again";
				cin>>gradebook[i][j];
			}
		}
	for(j=1;j<7;j++)
	{
		if(j=1)
		{
		cout<<"Enter exam 1:";
		cin>>gradebook[i][j];
		}
while(gradebook[i][j]>100||gradebook[i][j]<0)
			{
				cout<<"***Invalid grade***"<<endl;
				cout<<"Please Re-Enter";
				cin>>gradebook[i][j];
			}

		if(j=2)
		{
		cout<<"Enter exam 2:";
		cin>>gradebook[i][j];
		}
while(gradebook[i][j]>100||gradebook[i][j]<0)
			{
				cout<<"***Invalid grade***"<<endl;
				cout<<"Please Re-Enter";
				cin>>gradebook[i][j];
			}
		if(j=3)
		{
		cout<<"Enter final exam:";
		cin>>gradebook[i][j];
		}
while(gradebook[i][j]>100||gradebook[i][j]<0)
			{
				cout<<"***Invalid grade***"<<endl;
				cout<<"Please Re-Enter";
				cin>>gradebook[i][j];
			}
		if(j=4)
		{
		cout<<"Enter quiz 1:";
		cin>>gradebook[i][j];
		}
while(gradebook[i][j]>100||gradebook[i][j]<0)
			{
				cout<<"***Invalid grade***"<<endl;
				cout<<"Please Re-Enter";
				cin>>gradebook[i][j];
			}
		if(j=5)
		{
		cout<<"Enter quiz 2:";
		cin>>gradebook[i][j];
		}
while(gradebook[i][j]>100||gradebook[i][j]<0)
			{
				cout<<"***Invalid grade***"<<endl;
				cout<<"Please Re-Enter";
				cin>>gradebook[i][j];
			}
		if(j=6)
		{
		cout<<"Enter the proyect:";
		cin>>gradebook[i][j];
		}
while(gradebook[i][j]>100||gradebook[i][j]<0)
			{
				cout<<"***Invalid grade***"<<endl;
				cout<<"Please Re-Enter";
				cin>>gradebook[i][j];
			}
	}
	for(j=7;j<8;j++)
	{
		cout<<"Enter students' abscence";
		cin>>gradebook[i][j];
		while(gradebook[i][j]<0||gradebook[i][j]>20)
			{
				cout<<"**The number of abscences exceed the number of classes**"<<endl;
				cout<<"Re-enter: ";
				cin>>gradebook[i][j];
			}
			cout<<endl<<endl;
		}
	}
}
void Score(double gradebook[][9], int Students)
{
	int i, j;
	for (i=0; i<Students; i++)
	{
if (gradebook[i][0]==0)
		{
			cout<<"***No students were registered***.";
			cout<<"Select Option 1."<<endl;
			break;
		}
		else
		{
			for (i=0; i<Students; i++)
			{
				gradebook[i][8]=(gradebook[i][1]*0.15)+(gradebook[i][2]*0.15)+(gradebook[i][3]*0.30)+(gradebook[i][4]*0.10)+(gradebook[i][5]*0.10)+(gradebook[i][6]*0.20);
			}
			for (i=0; i<Students; i++)
			{
				if(gradebook[i][7]>=10)
					gradebook[i][8]=0;
				else
			{
					for(i=0; i<Students; i++)
					{
						for(j=0;j<gradebook[i][7];j++)
						{
							gradebook[i][8]-=1.0;
						}
						if(gradebook[i][8]<0)
							gradebook[i][8]=0;
					}
				}
			}
		}
		cout<<"***************ALL CALCULATION ARE MADE***************"<<endl<<endl;
	}
}




void Standev (double gradebook[][9], int Students)
	{
	int i, j, a, x;
	double sum, promedio, rum, letra, std_deviation;
	for(a=0; a<Students; a++)
		{
		if (gradebook[0][0]==0)
		{
			cout<<"No Grades were registered."<<endl;
			cout<<"Select Option 1."<<endl;
			break;
		}
		else if(gradebook[0][8]==-1)
		{
			cout<<"No calculations have been made nor grades were registrered."<<endl;
			cout<<"Select Option 2."<<endl<<endl<<endl;
			break;
		}
		else
		{
			do
			{
				cout<<"1.See the variance and standard deviation of the first exam."<<endl;
				cout<<"2.See the variance and standard deviation of the second exam."<<endl;
				cout<<"3.See the variance and standard deviation of the final exam."<<endl;
				cout<<"4.See the variance and standard deviation of the first quiz."<<endl;
				cout<<"5.See the variance and standard deviation of the second quiz."<<endl;
				cout<<"6.See the variance and standard deviation of the proyect."<<endl;
				cout<<"8.EXIT"<<endl;
				sum=0;
				rum=0;
				promedio;
				letra=0;
				std_deviation=0;
				x=0;
				cin>>x;
				while(x<1||x>8)
				{
					cout<<"***Error***Re-Enter.";
					cin>>x;
				}
				switch (x)
				{
				case 1:
				for(i=0; i<Students; i++)					
						for(j=1; j<2; j++)
							sum+=gradebook[i][j];
				promedio=sum/Students;
					for(i=0; i<Students; i++)					
						for(j=1; j<2; j++)
					rum+=(gradebook[i][j]-promedio)*(gradebook[i][j]-promedio);
					letra=rum/(Students-1);
					std_deviation=sqrt(letra);
					cout<<"Variance of first test is_"<<letra<<endl;
					cout<<"Standard deviation of first test is_"<<std_deviation<<endl<<endl;
					break;
				case 2:
				for(i=0; i<Students; i++)					
						for(j=2; j<3; j++)
							sum+=gradebook[i][j];
				promedio=sum/Students;
					for(i=0; i<Students; i++)					
						for(j=2; j<3; j++)
					rum+=(gradebook[i][j]-promedio)*(gradebook[i][j]-promedio);
					letra=rum/(Students-1);
					std_deviation=sqrt(letra);
					cout<<"Variance of second test is_"<<letra<<endl;
					cout<<"Standard deviation of second test is_"<<std_deviation<<endl<<endl;
					break;
				case 3:
				for(i=0; i<Students; i++)					
						for(j=3; j<4; j++)
							sum+=gradebook[i][j];
				promedio=sum/Students;
					for(i=0; i<Students; i++)					
						for(j=3; j<4; j++)
					rum+=(gradebook[i][j]-promedio)*(gradebook[i][j]-promedio);
					letra=rum/(Students-1);
					std_deviation=sqrt(letra);
					cout<<"Variance of final test is_"<<letra<<endl;
					cout<<"Standard deviation of final test is_"<<std_deviation<<endl<<endl;
					break;
				case 4:
				for(i=0; i<Students; i++)					
						for(j=4; j<5; j++)
							sum+=gradebook[i][j];
				promedio=sum/Students;
					for(i=0; i<Students; i++)					
						for(j=4; j<5; j++)
					rum+=(gradebook[i][j]-promedio)*(gradebook[i][j]-promedio);
					letra=rum/(Students-1);
					std_deviation=sqrt(letra);
					cout<<"Variance of first quiz is_"<<letra<<endl;
					cout<<"Standard deviation of first quiz is_"<<std_deviation<<endl<<endl;
					break;
				case 5:
				for(i=0; i<Students; i++)					
						for(j=5; j<6; j++)
							sum+=gradebook[i][j];
				promedio=sum/Students;
					for(i=0; i<Students; i++)					
						for(j=5; j<6; j++)
					rum+=(gradebook[i][j]-promedio)*(gradebook[i][j]-promedio);
					letra=rum/(Students-1);
					std_deviation=sqrt(letra);
					cout<<"Variance of second quiz is_"<<letra<<endl;
					cout<<"Standard deviation of second quiz is_"<<std_deviation<<endl<<endl;
					break;
				case 6:
				for(i=0; i<Students; i++)					
						for(j=6; j<7; j++)
							sum+=gradebook[i][j];
				promedio=sum/Students;
					for(i=0; i<Students; i++)					
						for(j=6; j<7; j++)
					rum+=(gradebook[i][j]-promedio)*(gradebook[i][j]-promedio);
					letra=rum/(Students-1);
					std_deviation=sqrt(letra);
					cout<<"Variance of proyect is_"<<letra<<endl;
					cout<<"Standard deviation of proyect is_"<<std_deviation<<endl<<endl;
					break;
				//default:
						//cout<<"INVALID SELECTION"<<endl;
				case 7: cout<<"EXIT"<<endl;
		
					break;

				default: cout<<"Invalid Selection"<<endl;
				}
			}
			while(x>=1&&x<=7);		
		}
		
	}
}







void Modif (double gradebook[][9], int Students)
{
int i, y, ng;
	if (gradebook[0][0]==0)//Nuevamente tiene que haber registrado notas para que esta funcion trabaje
	{
		cout<<"No student were registered"<<endl;
		cout<<"Please, select option 1."<<endl;
	}
	else
	{
		for(i=0; i<Students; i++)
		cout<<"Modify the student's grades in the order you entered them, or skip to other student.\n";
			cout<<"Student #" <<i+1<<"(ID# "<<gradebook[i][0]<<" )" <<endl<<endl;
			do
			{
				cout<<"1.Modify the grade of the first test."<<endl;
				cout<<"2.Modify the grade of the second test."<<endl;
				cout<<"3.Modify the grade of quiz 1."<<endl;
				cout<<"4.Modify the grade of quiz 2."<<endl;
				cout<<"5.Modify the grade of the project."<<endl;
				cout<<"6.Modify the grade of the FINAL TEST."<<endl;
				cout<<"7.Modify the absences."<<endl;
				cout<<"8.Skip this student, or to exit."<<endl<<endl;
				y=0;
				ng=0;
				cin>>y;
				while(y<1||y>8)
			{
					cout<<"***Invalid Option***\n Please Re-Enter: ";
					cin>>y;
				}
				switch (y)
				{
				case 1:
						cout<<"Enter new score for first test: ";
						cin>>ng;
						while(ng>100||ng<0)
						{
							cout<<"**Can't compute** Re-Enter: ";
							cin>>ng;
						}
						gradebook[i][1]=ng;
						cout<<"New value of the first test is: "<<gradebook[i][1]<<"%"<<endl<<endl;
						break;
				case 2:
						cout<<"Enter new score for second test: ";
						cin>>ng;
						while(ng>100||ng<0)
						{
							cout<<"**Can't compute** Re-Enter: ";
							cin>>ng;
						}
						gradebook[i][2]=ng;
						cout<<"New value of the second test is: "<<gradebook[i][2]<<"%"<<endl<<endl;
						break;
				case 3:
						cout<<"Enter new score for quiz 1: ";
						cin>>ng;
						while(ng>100||ng<0)
						{
							cout<<"**Can't compute** Re-Enter: ";
							cin>>ng;
						}
						gradebook[i][3]=ng;
						cout<<"New value of quiz 1 is: "<<gradebook[i][3]<<"%"<<endl<<endl;
						break;
				
				case 4: 
						cout<<"Enter new score for quiz 2: ";
						cin>>ng;
						while(ng>100||ng<0)
						{
						cout<<" **Can't compute** Re-Enter: ";
						cin>>ng;
						}
						gradebook[i][4]=ng;
						cout<<"New value of quiz 2 is: "<<gradebook[i][4]<<"%"<<endl<<endl;
						break;

				case 5:

						cout<<"Enter new score for project: ";
						cin>>ng;
						while(ng>100||ng<0)
						{
						cout<<" **Can't compute** Re-Enter: ";
						cin>>ng;
						}
						gradebook[i][5]=ng;
						cout<<"New value of project: "<<gradebook[i][5]<<"%"<<endl<<endl;
						break;

				case 6:
						cout<<"Enter new score for FINAL TEST ";
						cin>>ng;
						while(ng>100||ng<0)
						{
						cout<<" **Can't compute** Re-Enter: ";
						cin>>ng;
						}
						gradebook[i][6]=ng;
						cout<<"New value of FINAL TEST: "<<gradebook[i][6]<<"%"<<endl<<endl;
						break;
				
				case 7:
						cout<<"Enter new number of absences: ";
						cin>>ng;
						while(ng>20||ng<0)
						{
							cout<<"*******INCORRECT*******"<<endl;
							cout<<"Please re-enter: ";
							cin>>ng;
						}
						gradebook[i][7]=ng;
						cout<<"New value for absences is: "<<gradebook[i][7]<<endl<<endl;
						break;
				}
				if(y==8)
				{
					break;
				}
			}while(y>=1&&y<=7);
		}
			cout<<"Choose option 2 to calculate the new grades or abscents"<<endl<<endl;

}



void ViewGrades (double gradebook[][9], int Students)
{
	int i, j, k; 
	double note=0;
	char x;
if (gradebook[0][0]==0)
		cout<<"ID numbers were not entered. Select to option 1."<<endl<<endl;
	else if(gradebook[0][8]==-1)
		cout<<"Calculations haven't been made. Select option 2."<<endl<<endl;
	else
	{
	for(i=0; i<Students; i++)
		{
			for(j=0; j<1; j++)
			{
				cout<<"The scores for student's tests are:\n";
				for(k=1; k<7; k++)
					cout<<gradebook[i][k]<<"%"<<endl;
				cout<<"With ";
				for(k=7; k<8; k++)
					cout<<gradebook[i][k];
				cout<<"Abscences to class."<<endl;
				cout<<"Final grade is";
				if (gradebook[i][8]<=100&&gradebook[i][8]>=90)
					x='A';
				else if (gradebook[i][8]<=89&&gradebook[i][8]>=80)
					x='B';
				else if (gradebook[i][8]<=79&&gradebook[i][8]>=70)
					x='C';
				else if (gradebook[i][8]<=69&&gradebook[i][8]>=60)
					x='D';
				else
					x='F';
				cout<<x<<"(";
				for(k=9; k<10; k++)
					cout<<gradebook[i][8];
				cout<<"%)."<<endl<<endl;
			}
		}
	}
}

First of all what scope is your gradebook[][] array declared in?

Try putting this for your Modif() function:

void *Modif (double gradebook[][9], int Students)

Not 100% sure if that will even do anything but I think it might change your array.

The scope of the array is just fine and it gets passed by addres so you're fine there too ...

DO NOT return void * ... why would you do that ? ( as the last post said)

My suggestion is that the "mechanics" are fine but the "logic" part may be faulty; try running it step-by-step in the debugger and check which condition is wrong.

Hi Sfuo

Santhosh here, i dont know the for loop u have taken to calculate absence u have given j=8 and j<9 that means it will only taken one value there where in u have to check how many days he is absent when u do this u will obviously get the answer as fail.

this is what i thought it may be right or wrong why cant u try that.

Look at where you are calculating their grades.

You have a for() loop that checks through the students to see if they have 10 absences or not then after that loop it goes to another loop that calculates their grade.

You want to take out the 2nd loop because it overwrites the final grade = 0 done by the 10 absences.

I see no problem with your modif() function unless you changed it in any way other than setting the indexes from your first post.

I have been following this grade book with a lot of interest. Wht was the final solution? did it work well?

This article has been dead for over six months. Start a new discussion instead.