### Working with 2D arrays

I am working on a project using 2D arrays to display a class's individual grades, averages, and a class average. I am able to display the grades and class average, but my STUDENT AVERAGE Letter Grade is returning a number, when I thought my if else ladder was telling it to return the Char. Any help would be much appreciated.

 ``123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129`` ``````#include #include using namespace std; //file level scope const int columns = 4; const int nColumns = 20; //prototype for 2d array void showNamesAndScores(int scores[][columns], char names[][nColumns], int); //calcAvg double calcAvg(int X[][columns], int); //studentAvg char studentAvg(int X[][columns], int); int main() { //declare rows & columns const int rows = 5; //declare 2d array int scores[rows][columns]; char names[rows][nColumns]; //populate 2d array for(int i=0; i>names[i]; cout<>scores[i][j]; } } //display scores with function showNamesAndScores(scores, names, rows); //display avg double avg = calcAvg(scores, rows); cout<<"Avg: "<= 90) grade = 'A'; else if(avg >= 80 && avg < 90) grade = 'B'; else if(avg >= 70 && avg < 80) grade = 'C'; else if(avg >= 60 && avg < 70) grade = 'D'; else grade = 'F'; return grade; }//endstudentAvg ``````
Last edited on
I believe it is something very simple that I am also overlooking. In the bottom of your function studentAvg could you put in a cout << grade to see what it does and let me know.
apparently these kids ace their tests. i input 100s for all grades. should be an A where that F is right?

 ```[Session started at 2009-11-02 22:20:14 -0600.] Enter Name of student1: bob Enter Name of student2: tim Enter Name of student3: john Enter Name of student4: matt Enter Name of student5: alice Enter 4 scores for row 1: 100 100 100 100 Enter 4 scores for row 2: 100 100 100 100 Enter 4 scores for row 3: 100 100 100 100 Enter 4 scores for row 4: 100 100 100 100 Enter 4 scores for row 5: 100 100 100 100 bob 100 100 100 100 tim 100 100 100 100 john 100 100 100 100 matt 100 100 100 100 alice 100 100 100 100 Avg: 100 F Letter Grade: 70 The Debugger has exited with status 0.```
UPDATE:

 ``123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168`` ``````#include #include #include using namespace std; //file level scope const int columns = 4; const int nColumns = 20; //prototype for 2d array void showNamesAndScores(int scores[][columns], char names[][nColumns], int); //calcAvg double calcAvg(int X[][columns], int); //studentAvg char studentAvg(int X[][columns], int); //deviation void deviation(int X[][columns], double Y[][columns], int, double); //variance void variance(double Y[][columns],int); int main() { //declare rows & columns const int rows = 5; //declare 2d array int scores[rows][columns]; char names[rows][nColumns]; //populate 2d array for(int i=0; i>names[i]; cout<>scores[i][j]; } cout<= 90) grade = 'A'; else if(avg >= 80 && avg < 90) grade = 'B'; else if(avg >= 70 && avg < 80) grade = 'C'; else if(avg >= 60 && avg < 70) grade = 'D'; else grade = 'F'; cout<<"Letter Grade: "; return grade; }//endstudentAvg //calcDeviation void deviation(int scores[][columns],double devi[][columns], int rows, double avg) { for(int i=0; i
Topic archived. No new replies allowed.