Hi, i have a problem with this code, which is it only takes the last scores entered by the user when i want to take all the scores of each student and do the avrage calculation and display them like the output ill post with the question.

Np Ms Office 365/Excel 2016 I Ntermed
1st Edition
ISBN:9781337508841
Author:Carey
Publisher:Carey
Chapter1: Getting Started With Excel
Section: Chapter Questions
Problem 3.16CP
icon
Related questions
Question

Hi, i have a problem with this code, which is it only takes the last scores entered by the user when i want to take all the scores of each student and do the avrage calculation and display them like the output ill post with the question.

The code:

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

void readStudentInfo (string [],int,double[]);

void calcAvg (double[],int);

char getGrade (char[],int, double);

void printResults(string[],double[],double[],int);

 

void line()
{
    cout << "--------------------------------";
}

 

const int N=2; // Number of students
const int S=5; // Number of tests

int main()
{
    string StName[N];
    double StScore[S];
    
    printResults(StName,StScore,StScore,N);
    
}


void readStudentInfo(string names[],int students,double Average[],double Score[])
{
        
    for (int i=0; i<students;i++)
    {
        cout << "Please enter student name (" << i+1 << "): ";
        getline(cin, names[i]);
        cout << "\n";
    }
    
    
    for (int j=0; j<students;j++)
    {
        cout << "Enter all " << S << " scores for " << names[j] << " : " << "\n";
        
        for (int x=0; x<S; x++)
        {
        cin >> Score[x];
        Average[x]+=Score[x];
        }
        
    }    

}


void calcAvg (string names[], double Average[],int students,double Score[])
{
    double     StSum=0;
    for (int i=0; i<students;i++)
    {
        StSum=0;  
        for (int j=0; j<S*N; j++)
        {
        StSum+=Score[j];
        }
        cout <<" StSum: " << StSum << endl;
    
    Average[i] = StSum/S;        
    cout << "AVERAGE IS: " << Average[i] << endl;
    
    }

    
}

 

void printResults(string names[],double Score[],double Average[],int students)
{
    
    readStudentInfo(names,students,Average, Score);
    
    double classAvg=0,scoreSum=0;
    char grade[N],tempGrade[1],ClassGrade;
    double tempAvg=0;

    
    
    calcAvg(names,Score,students, Score);
    
    
    for (int x=0;x<students;x++)
    {
        tempAvg = Average[x];
        grade[x] = getGrade(grade,students,tempAvg);
        
        classAvg+= Average[x];
    }
        classAvg= classAvg/N;

        ClassGrade = getGrade(tempGrade,students,classAvg);        
        
        cout << "\n";
        
        
        line ();    
        cout << "\n";
        cout << "Class Average: " << classAvg    << endl;
        cout << "Class Grade  : " << ClassGrade  << endl;
        line ();

        
        cout << "\n";
                
    for (int i=0; i<students; i++)
    { 

        cout << "    Name: "    << names[i]   << endl;
        cout << " Average: "    << Average[i] << endl;
        cout << "   Grade: "    << grade[i]   << endl;
        line ();
        cout << "\n";

    }
    
}


char getGrade (char grade[],int students, double Avg)
{
        if (Avg>=90)
        return 'A';
        if (Avg>=80)
        return 'B';
        if (Avg>=70)
        return 'C';
        if (Avg>=60)
        return 'D';        
        if (Avg<60)
        return 'F';
}

 

Please enter student name (1): zack
Please enter student name (2): jack
Enter all 5 scores for zack :
100 100 90 90 90
Enter all 5 scores for jack :
90 90 90 90 90
StSum: 900
AVERAGE IS: 180
StSum: 900
AVERAGE IS: 180
Class Average: 180
Class Grade : A
Name: zack
Average: 180
Grade: A
Name: jack
Average: 180
Grade: A
Transcribed Image Text:Please enter student name (1): zack Please enter student name (2): jack Enter all 5 scores for zack : 100 100 90 90 90 Enter all 5 scores for jack : 90 90 90 90 90 StSum: 900 AVERAGE IS: 180 StSum: 900 AVERAGE IS: 180 Class Average: 180 Class Grade : A Name: zack Average: 180 Grade: A Name: jack Average: 180 Grade: A
Expert Solution
steps

Step by step

Solved in 3 steps with 2 images

Blurred answer
Knowledge Booster
Print statement
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Np Ms Office 365/Excel 2016 I Ntermed
Np Ms Office 365/Excel 2016 I Ntermed
Computer Science
ISBN:
9781337508841
Author:
Carey
Publisher:
Cengage
Programming with Microsoft Visual Basic 2017
Programming with Microsoft Visual Basic 2017
Computer Science
ISBN:
9781337102124
Author:
Diane Zak
Publisher:
Cengage Learning
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT