so here is my code which trying to find the highest avg using different methods I managed to get the first two but I am stuck on the third method which needs a pointer to pointer of type student(struct).
#include <iostream>
using namespace std;
struct student
{
char Name[100];
float avg;
};
student highest(student A[], int size) {
student max = A[0];
for (int i = 1; i < size; i++)
if (max.avg < A[i].avg)
max = A[i];
return max;
}
student* highest1(student A[], int size) {
int highest = 0;
for (int i = 0; i < size; i++) {
if (A[highest].avg < A[i].avg)
highest = i;
}
student* max = &A[highest];
return max;
}
student highest2(student** A, int row, int col) {
int maxi=0, maxj=0;
int i = 0, j = 0;
for ( i = 0; i < row; i++) {
for ( j = 0; j < col; j++)
if (A[maxi][maxj].avg < A[i][j].avg)
maxi = i; maxj = j;
}
return A[maxi][maxj];
}
int main() {
cout << "please enter teh number of students " << endl;
int x;
int row, col, test;
cin >> x;
student *A = new student[x];
student B[3][2];
cout << "please enter the name of the "<<x<<" students " << endl;
for (int i = 0; i < x; i++) {
gets_s(A[i].Name, 100);
}
cout << "please enter the average for" <<x<<" students " << endl;
for (int i = 0; i < x; i++)
cin >> A[i].avg;
//cout << "the highest grade is " << highest(A,x).avg << endl;
//cout << highest1(A, x)->avg;
highest2(B, 3, 2);
}
so of course after inputting the information into the matrix of the 3x2 i have to check that and that is the issue I don't understand how I can manage to send it to the function, I tried some way but I would get a logical error in which the code would check only 1 row.