I have a program to calculate and show the grades for 4 students and 3 tests. I want to calculate the average for each student, the average of the test scores for each test, and the average of the student average. I also want the program to give a letter grade after calculating the average for the students. I'm not sure how to do that.
#include <iostream>
using namespace std;
void printArray(int [][3], int, int);
void main(){
//declare a 2-d aray
//each row is for a student and each column for a grade
int course [4][3];
int columns = sizeof(course[0])/sizeof(int);
int rows = (sizeof(course)/sizeof(int))/(sizeof(course[0])/sizeof(int));
int grade;
//enter the grades per student(by rows in a column)
for(int i = 0; i < columns; i++){
for(int j = 0; j < rows; j++){
cout << "\nEnter the grade for test number " << i + 1 << " for student number " << j + 1 << ":";
cin >> grade;
course[j][i] = grade;
}
}
printArray(course, rows, columns);
//int prueba [][3] = {{1,2,3},{4,5,6},{7,8,9}};
//printArray(prueba,3,3);
system("pause");
}
void printArray( int anArray[][3], int rows, int cols){
cout << "Student\tTest 1\tTest 2\tTest 3\n";
for(int i = 0; i < rows; i++){
cout << i + 1 << "\t";
for(int j = 0; j < cols; j++){
cout << anArray[i][j] << "\t";
}
cout << endl;
}
cout << endl;
}
//the range for the letter avg are:
//A = 90 - 100
//B = 80 - 89
//C = 70 - 79
//D = 60 - 69
//F = 0 - 59
here is an example of the output of the program right now:
Student Test1 Test2 Test3
1 100 98 97
2 100 97 98
3 100 98 99
4 100 97 99
here is an example of the output as i want it to be shown:
Student Test1 Test2 Test3 Student Avg Letter Grade
1 100 98 97 98 A
2 100 97 98 98 A
3 100 98 99 99 A
4 100 97 99 98 A
Test Avg. 100 97 98 98
main()
should be of typeint
, notvoid
. More info about that here. – Jamal♦ Jul 8 '13 at 1:47