i tried many times already , still cant get the solution that i wan.

//How to define a function named highest that determines the highest average //mark?
//i tried my best already, but still cant get the highest average mark.

#include<iostream>
#include<iomanip>
using namespace std;
#define n 10


double find_average(double );
void find_highestAverage(double);
void Array();
void display_grade();
int storeAverage[10];
const int No_matric=10;
const int matricNo=7;
const int row_Scores=10;
const int col_Scores=3;
double average,total,largest;
int row;


char noMatrix[No_matric][matricNo] ={"BC0123","BC1234","BC2345","BC3456","BC4567","BC5678","BC6789","BC7890","BC8900","BC9999"};
double scores[row_Scores][col_Scores]={{84.2,86.4,79.8},{93.2,87.4,65.4},{86.0,83.5,84.5},{30.0,50.5,80.2},{54.9,78.8,90.3},
{45.7,63.8,50.2},{78.4,47.6,68.7},{88.8,73.2,87.6},{78.7,40.3,59.6},{67.9,77.8,90.1}};
int main()
{




cout<<"\tBITP1113 : Students' Performance Report"<<endl;
cout<<"\t---------------------------------------"<<endl;
cout<<" Matric no.\tTest1\tTest2\tTest3\tAverage"<<" "<<"Grade"<<endl;
cout<<" ---------\t-----\t-----\t-----\t-------"<<" "<<"-----"<<endl;


for(row=0; row<10;row++)
{
cout<<"\n"" "<<noMatrix[row];

for(int col=0;col<3;col++)
{
cout<<"\t"<<setprecision(2)<<fixed<<scores[row][col];
}

average = find_average(average);
cout<<setprecision(2)<<fixed<<" \t "<<average<<"\t ";
display_grade();
find_highestAverage(average);

}



return 0;
}


double find_average(double average)
{

{
double total;
total =scores[row][0]+scores[row][1]+scores[row][2];
average= total/3;

}

return average;
Array();

}

void display_grade()
{
if(average>=80 && average<=100)
cout<<" A"<<endl;

else if (average>=70 && average<=79.9)
cout<<" B"<<endl;

else if(average>=60 && average<=69.9)
cout<<" C"<<endl;

else if (average>=40 && average<=59.9)
cout<<" D"<<endl;

else
cout<<" E"<<endl;
}




void Array()
{
for(int a=0;a<10;a++)
cin>>storeAverage[a];

}



void find_highestAverage(double numbers)
{


double highest=0;

if (numbers > highest)
{
highest=numbers;
cout<<highest<<endl;
}
cout<<highest<<endl;
}
Use code tags when posting snippets. That way, it's easier for us to read and point out mistakes.

You're missing some logic:
-Array() stores the values 0 to 9, not the averages. You should have a function store(double avg) that stores the row's average into the array.
-find_highestAverage checks a single value versus 0, then prints and discards. It should be looping through storeAverages to find the highest value.
//i correct some of the coding, but still cant show the highest average scores.
//can u help me to find out.


#include<iostream>
#include<iomanip>
using namespace std;
#define n 10

double find_average(double );
void storeArray(double);
void display_grade();
void find_highest();
double storeAverage[n];
const int No_matric=10;
const int matricNo=7;
const int row_Scores=10;
const int col_Scores=3;
double average,total,arrays;
int row;


char noMatrix[No_matric][matricNo] ={"BC0123","BC1234","BC2345","BC3456","BC4567","BC5678","BC6789","BC7890","BC8900","BC9999"};
double scores[row_Scores][col_Scores]={{84.2,86.4,79.8},{93.2,87.4,65.4},{86.0,83.5,84.5},{30.0,50.5,80.2},{54.9,78.8,90.3},
{45.7,63.8,50.2},{78.4,47.6,68.7},{88.8,73.2,87.6},{78.7,40.3,59.6},{67.9,77.8,90.1}};
int main()
{




cout<<"\tBITP1113 : Students' Performance Report"<<endl;
cout<<"\t---------------------------------------"<<endl;
cout<<" Matric no.\tTest1\tTest2\tTest3\tAverage"<<" "<<"Grade"<<endl;
cout<<" ---------\t-----\t-----\t-----\t-------"<<" "<<"-----"<<endl;


for(row=0; row<10;row++)
{
cout<<"\n"" "<<noMatrix[row];

for(int col=0;col<3;col++)
{
cout<<"\t"<<setprecision(2)<<fixed<<scores[row][col];
}

average = find_average(average);
cout<<setprecision(2)<<fixed<<" \t "<<average<<"\t ";
display_grade();
find_highest();
}

return 0;
}


double find_average(double average)
{
{
double total;
total =scores[row][0]+scores[row][1]+scores[row][2];
average= total/3;
}
return average;


}

void display_grade()
{
if(average>=80 && average<=100)
cout<<" A"<<endl;

else if (average>=70 && average<=79.9)
cout<<" B"<<endl;

else if(average>=60 && average<=69.9)
cout<<" C"<<endl;

else if (average>=40 && average<=59.9)
cout<<" D"<<endl;

else
cout<<" E"<<endl;
}




void storeArray(double arrays)
{
for(int a=0;a<10;a++)
cin>>storeAverage[a];

}

void find_highest()
{
int b;
double largest, storeAverage[n];
storeArray(arrays);
for( b=0;b<10;b++)
largest=storeAverage[0];

for(b=1;b<10;b++)
{
if (largest<storeAverage[b])
largest=storeAverage[b];
}
cout<<largest;
}

If you want them to line up, change one of the lines.

The line that looks like this :
cout<<"\n"" "<<noMatrix[row];

change it to look like this :
cout<<"\n"" "<<noMatrix[row]<<"\t";

It shows all info in the correct spots now. And I am seeing the average score from this.
Last edited on
i wan to find is define a function named highest that determines the highest average
So this function you have here is not it ?

1
2
3
4
5
6
7
8
9
double find_average(double average)
{
   {
     double total;
     total =scores[row][0]+scores[row][1]+scores[row][2];
     average= total/3;
   }
   return average;
}


I guess I'm confused as to what your trying to do.
Last edited on
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
void find_highest()
{
int b;
double largest, storeAverage[n];
storeArray(arrays);
for( b=0;b<10;b++)
largest=storeAverage[0];

for(b=1;b<10;b++)
{
if (largest<storeAverage[b])
largest=storeAverage[b];
}
cout<<largest;
}

I don't think you fully understand what you're trying to do here. You should really read up on function and variable scopes.
Last edited on
I agree Gaminic. I thought about using that function to ask him about, but I choose the one I posted in order to determine what he is wanting in the first place. I'm a little confused by his question since his answer seems to be answered already in the code.
my question is , although i write the function to find the highest average mark/score(i did not know whether the coding is correct or not), but i can't store the average mark into a new array, and then use the array to compare all the scores 1 by 1 to find which is the highest averaged score. Besides i also dont know where to put the find_highest() function ??
Ok I had to change some of your code to get this to work :

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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#include<iostream>
#include<iomanip>
using namespace std;
#define n 10

double find_average(double );
void storeArray(double);
void display_grade();
void find_highest();
double storeAverage[n];
const int No_matric=10;
const int matricNo=7;
const int row_Scores=10;
const int col_Scores=3;
double average,total,arrays;
int row;
int col;



char noMatrix[No_matric][matricNo] ={"BC0123","BC1234","BC2345","BC3456","BC4567","BC5678","BC6789","BC7890","BC8900","BC9999"};
double scores[row_Scores][col_Scores]={{84.2,86.4,79.8},{93.2,87.4,65.4},{86.0,83.5,84.5},{30.0,50.5,80.2},{54.9,78.8,90.3},
{45.7,63.8,50.2},{78.4,47.6,68.7},{88.8,73.2,87.6},{78.7,40.3,59.6},{67.9,77.8,90.1}};
int main()
{

cout<<"\tBITP1113 : Students' Performance Report"<<endl;
cout<<"\t---------------------------------------"<<endl;
cout<<" Matric no.\tTest1\tTest2\tTest3\tAverage Grade\t"<<"Highest Score"<<endl;
cout<<" ---------\t-----\t-----\t-----\t------- -----\t-------------"<<endl;


for(row=0; row<10;row++)
{
  cout<<"\n"" "<<noMatrix[row]<<"\t";

  for(int col=0;col<3;col++)
  {
    cout<<"\t"<<setprecision(2)<<fixed<<scores[row][col];
  }

  average = find_average(average);
  cout<<setprecision(2)<<fixed<<" \t "<<average<<"\t ";
  display_grade();
  find_highest();
  }

  return 0;
}


double find_average(double average)
{
  {
    double total;
    total =scores[row][0]+scores[row][1]+scores[row][2];
    average= total/3;
  }
  return average;
}

void display_grade()
{
  if(average>=80 && average<=100)
  cout<<" A"<<endl;

  else if (average>=70 && average<=79.9)
  cout<<" B"<<endl;

  else if(average>=60 && average<=69.9)
  cout<<" C"<<endl;

  else if (average>=40 && average<=59.9)
  cout<<" D"<<endl;

  else
  cout<<" E"<<endl;
}




void find_highest()
{
  int b;
  double largest, storeAverage[n];

 largest=scores[row][col];

  for(b=0;b<3;b++)
    {
      if (largest<=scores[row][b])
      {
        largest=scores[row][b];
      }
    }
  cout<<largest<<endl;
}


The problem was in the find_highest() function. It was looking at your averages for your highest number. But the averages has no way to check in any other number except itself. So What you needed was the actual Score Numbers itself to compare each one individually.

Now, if your wanting to compare ALL the high scores, then you need to create an array and store those numbers into it and then call each of those numbers separately. All ten of them. And from there display the highest out of all ten. So the bottom line is which set of numbers are you trying to compare.
Last edited on
Topic archived. No new replies allowed.