2017-01-25 6 views
-9

このプログラムでは、10人の学生のすべての成績を処理する必要があります。 各生徒の氏名、ID番号、 3つの宿題、3つのラボのグレード、3つのテストグレード、1つの最終試験グレードがあります。 番号とレターの両方で最終学年を表示10人の平均成績を取得するC++

等式は、最初の等級にのみ作用し、次の平均に少し追加します。何が間違っているのか分かりません。

/*This program will need to handle all grades for 10 students. 
Each student has a first and last name, an id number, 
3 homework grades, 3 labs grades, 3 test grades, and 1 final exam grade. 
display the final course grade in both numbered and letter version 
*/ 
#include <iostream> // main library 
#include <string> //enables use of strings 
#include <iomanip> // for setw 
#include <Windows.h> // used to set console title 
using namespace std; // for cout and cin 

const int MAXSTUDENTS = 2; 
const int MAXGRADES = 3; 
const int MINGRADES = 1; 

int main() 
{// Get names form students 

    SetConsoleTitle("Gradebook"); 
    double hwGrade[MAXSTUDENTS][MAXGRADES]; 
    double labGrade[MAXSTUDENTS][MAXGRADES]; 
    double testGrade[MAXSTUDENTS][MAXGRADES]; 
    double feGrade[MAXSTUDENTS]; 
    double final_num_grade[MAXSTUDENTS]; 
    double hwAve =0, labAve=0, testAve=0;          // this will be used to calculate the averages 
    string fName[MAXSTUDENTS]; 
    string lName[MAXSTUDENTS]; 
    string line;               // to set the two string variables 
    string id[MAXSTUDENTS];                   // id will be a whole number so int was apropiate 
    //first for statement. ensuere that the program is run 10 times 

    for (int s = 0; s < MAXSTUDENTS; s++) { 
     cout << "Enter student's first name: ";         // ask the user for the first name 
     getline(cin, fName[s]);                // accepts students first name 
     cout << "Enter stedent's last name: ";          //ask the user for last name 
     getline(cin, lName[s]);                // accepts students last name 
     cout << "Enter student's id:  ";         // ask user for student id 
     getline(cin, id[s]); 



     // this loop will ask for three homework grades 
     for (int n = 0; n < MAXGRADES; n++) { 

      cout << "Homework grade " << n + 1 << " is  ";         //tells the user waht the program needs 
      cin >> hwGrade[s][n];                //lets the user input the homework grades 
      hwAve += hwGrade[s][n]; 
     } 
     hwAve = hwAve/3; 

     // this loop will ask for three lab grades 
     for (int l = 0; l < MAXGRADES; l++) { 
      cout << "Lab grade " << l + 1 << " is   "; 
      cin >> labGrade[s][l];              //lets the user input the LAB grades 
      labAve += labGrade[s][l]; 
     } 
     labAve = labAve/3; 


     //this loop will ask for three test grades 
     for (int t = 0; t < MAXGRADES; t++) { 
      cout << "Test grade " << t + 1 << " is   "; 
      cin >> testGrade[s][t];             //lets the user input the test grades 
      testAve += testGrade[s][t];           // the average is calculated 
     } 
     testAve = testAve/3; 



      cout << "Final exam grade:  ";           // asks user for final exam grade 
      cin >> feGrade[s]; 


      // equation to get the final course grade 

      final_num_grade[s] = (hwAve * 0.20) + (labAve * 0.25) + (testAve * 0.30) + (feGrade[s] * 0.25); 
      line.assign(50, '-'); 
      cout << line << endl; 

    } 

    for (int i = 0; i < MAXSTUDENTS; i++) { 
     cout << "Final Course Grade for " << fName[i] << " " << lName[i] << " with the id " << id[i] << " is "   // displays name of student 
      << showpoint << fixed << setprecision(1) << final_num_grade[i];  //set to 1 decimal place 
                         //if statement shows the letter grade 
     if (final_num_grade[i] >= 89.5) {             //A if student made 89.5 or more 
      cout << " (A)\n"; 
     } 
     else if (final_num_grade[i] >= 79.5) {             //B if student made 79.5 to 89.4 
      cout << " (B)\n"; 
     } 
     else if (final_num_grade[i] >= 69.5) {             // C if student made 69.5 yo 79.4 
      cout << " (C)\n"; 
     } 
     else if (final_num_grade[i] >= 59.5) {             // D if student made 59.5 to 69.4 
      cout << " (D)\n"; 
     } 
     else {                    // F if student made less than 59.4 
      cout << " (F)\n"; 
     } 
    } 
    return 0; 
} 
+1

がhttp://stackoverflow.com/help/mcve若干高くなりますhwAve, labAve, testAve - あなたはあなたの実際のコードをポストする必要がありますがそれは動作していません – xaxxon

+0

ここにあなたのコードをデバッグするために投稿してください。 – instance

答えて

0

あなたはゼロにこれらの変数をリセットしていない。第二学生のグレードは

関連する問題