Help with c++ homework please and thank you.

I can run the program but for some reason the average doesn't come out right and the numbers next to it don't match the test scores when they sort.


// compiler directives
#include <iostream>
#include<iomanip>
#include<stdio.h>

using namespace std;

// constant identifiers
const int MAXSIZE = 10;

// function prototypes
void GetData(int TestScoresf[]);
void ComputeAvg(int TestScoresf[],float &Avgf);
void PrintReport(int TestScoresf[],float Avgf);
// main program
int main()
{
// local identifiers
int TestScores[MAXSIZE];
float Avg;
//Input modale
GetData(TestScores);
//processing module
ComputeAvg(TestScores,Avg);
//output module
PrintReport(TestScores,Avg);

system ("PAUSE");
return 0 ;
}//end main

// function definitions
void GetData (int TestScores[ ])
{
for (int i=0; i <MAXSIZE; i++)
{
cout<<"please enter the test score #"<<i+1<<":\t";
cin>>TestScores[i];
}



return;
}

// end GetData

void ComputeAvg( int TestScoresf[],float&Avgf)

{

int sum = 0;
for(int i=0; i <MAXSIZE; i++)
{
sum = TestScoresf[i];
}
Avgf = float(sum)/MAXSIZE;
return;
} //end ComputeAvg

void PrintReport (int TestScoresf[], float Avgf)
{
cout<<setw(23)<<"Test#"<<setw(15)<<"Test…
cout<<"\n\n";
for(int i = 0; i <MAXSIZE; i ++)
{
cout<<setw(26)<<i+1<<setw(20)<<TestScore…
}
cout<<"\n\n"<<fixed<<showpoint<<setpreci…
cout<<"test score average:\t"<<Avgf<<endl;
return;
}
// end print Report
void printsorted (int TestScoresf[])
{
return ;
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
// compiler directives
#include <iostream>
#include<iomanip>
#include<stdio.h>

using namespace std;

// constant identifiers
const int MAXSIZE = 10;

// function prototypes
void GetData(int TestScoresf[]);
void ComputeAvg(int TestScoresf[],float &Avgf);
void PrintReport(int TestScoresf[],float Avgf);
// main program
int main()
{
    // local identifiers
    int TestScores[MAXSIZE];
    float Avg = 0;//remember to set equal to 0
    //Input modale
    GetData(TestScores);
    //processing module
    ComputeAvg(TestScores,Avg);
    //output module
    PrintReport(TestScores,Avg);
    
   // system ("PAUSE"); REMOVE THIS
    return 0 ;
}//end main

// function definitions
void GetData (int TestScores[ ])
{
    for (int i=0; i <MAXSIZE; i++)
    {
        cout<<"please enter the test score #"<<i+1<<":\t";
        cin>>TestScores[i];
    }
    
    
    
    return;
}

// end GetData

void ComputeAvg( int TestScoresf[],float&Avgf)

{
    
    int sum = 0;
    for(int i=0; i <MAXSIZE; i++)
    {
        sum += TestScoresf[i];//change to += otherwise you are replacing the value each time
    }
    Avgf = float(sum)/MAXSIZE;
    return;
} //end ComputeAvg

void PrintReport (int TestScoresf[], float Avgf)
{
    cout<<setw(23)<<"Test#"<<setw(15)<<"Test…";
    cout<<"\n\n";
    for(int i = 0; i <MAXSIZE; i ++)
    {
        cout<<setw(26)<<i+1<<setw(20)<<TestScoresf; 
    }
    cout<<"\n\n"<<fixed<<showpoint<<setprecision(3);
    cout<<"test score average:\t"<<Avgf<<endl;
    return;
}
// end print Report
void printsorted (int TestScoresf[])
{
    return ;
} 
Topic archived. No new replies allowed.