This is a pretty simple program, but I am still having problems, and my CompSci teacher has been out for a couple of weeks.
Code:/* Lenavich III Period 6 This program computes the average, G.P.A., and letter grades of 20 different students, as well as outputting that in a table when given the names of the 20 different students and a number of their grades. */ #include <iostream.h> #include <iomanip.h> #include <windows.h> #include <math.h> int main() { char names[4][10]; // array of students names char lgrade[4][3]; // letter grade variable double average[4]; // average of grades variable double gpa[4]; // G.P.A variable int h, i; // counter int grades; // number of grades variable double total; double grade;// int honors; // querying user for number of grades cout << "How many grades would you like to enter per a student?" << endl; cin >> grades; // querying user for names of students for(i = 0; i <= 4; i++) { cout << "Enter a student's name whose grade you wish to compute." << endl; cin >> names[i]; cout << endl; } // querying user for grades for( i = 0; i <= 4; i++) { for ( h = 1; h <= grades; h++) { cout << "Please enter one of " << names[i] << "'s grades" << endl; cin >> grade; total = total + grade; } } average[i] = total / grades; for( i = 0; i <= 4; i++) { if(average[i] < 60) { lgrade[i][0] = 'F'; lgrade[i][1] = ' '; } else if(average[i] < 63) { lgrade[i][0] = 'D'; lgrade[i][1] = '-'; } else if(average[i] < 67) { lgrade[i][0] = 'D'; lgrade[i][1] = ' '; } else if(average[i] < 70) { lgrade[i][0] = 'D'; lgrade[i][1] = '+'; } else if(average[i] < 73) { lgrade[i][0] = 'C'; lgrade[i][1] = '-'; } else if(average[i] < 77) { lgrade[i][0] = 'C'; lgrade[i][1] = ' '; } else if(average[i] < 80) { lgrade[i][0] = 'C'; lgrade[i][1] = '+'; } else if(average[i] < 83) { lgrade[i][0] = 'B'; lgrade[i][1] = '-'; } else if(average[i] < 87) { lgrade[i][0] = 'B'; lgrade[i][1] = ' '; } else if(average[i] < 90) { lgrade[i][0] = 'B'; lgrade[i][1] = '+'; } else if(average[i] < 93) { lgrade[i][0] = 'A'; lgrade[i][1] = '-'; } else if(average[i] < 97) { lgrade[i][0] = 'A'; lgrade[i][1] = ' '; } else { lgrade[i][0] = 'A'; lgrade[i][1] = '+'; } } for( i = 0; i <= 4; i++) { if (average[i] >= 97 ) { gpa[i] = 4.3; } else if(average[i] >= 93) { gpa[i] = 4.0; }else if(average[i] >= 90) { gpa[i] = 3.7; } else if(average[i] >= 87) { gpa[i] = 3.3; } else if(average[i] >= 83) { gpa[i] = 3.0; } else if(average[i] >= 80) { gpa[i] = 2.7; } else if(average[i] >= 77) { gpa[i] = 2.3; } else if(average[i] >= 73) { gpa[i] = 2.0; } else if(average[i] >= 70) { gpa[i] = 1.7; } else if(average[i] >= 67) { gpa[i] = 1.3; } else if(average[i] >= 63) { gpa[i] = 1.0; } else if(average[i] >= 60) { gpa[i] = .7; } else{ gpa[i] = 0.0; } if(gpa[i] >= 4.0) { honors = 1; } } // table cout << endl << "Name" << setiosflags(ios::fixed||ios::showpoint) << setprecision(5) << "GPA" << setiosflags(ios::fixed||ios::showpoint) << setprecision(5) << "Letter Grade" << endl; for(i = 0; i <= 4; i++) { cout << endl; if(honors = 1) { cout << names[i] << gpa[i]<< lgrade[i] << "High Honors" << endl; } else { cout << names[i] << gpa[i] << lgrade[i] << endl; } } return 0; }



LinkBack URL
About LinkBacks


