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
|
#include <iostream>
#include <cstdlib>
using namespace std;
const int ROWS=3;
const int STUDENTS=4;
void highest(int math[][STUDENTS],int highestGrade[],int highLocation[],int i)
{
int high=0;
for (int x=0;x<STUDENTS;x++)
{
if (math[i][x]>high)
{
high=math[i][x];
highestGrade[i]=high;
highLocation[i]=x;
}
}
}
void lowest(int math[][STUDENTS],int lowestGrade[],int lowPosition[],int i)
{ int position=0;
int low=math[i][0];
for (int z=0;z<STUDENTS;z++)
{
if (low>math[i][z])
{
low=math[i][z];
lowestGrade[i]=low;
position=z;
lowPosition[i]=position; // having problem here, i don't know why is always 0.
}else
lowestGrade[i]=low;
lowPosition[i]=0;
}
cout <<"lowestGrade "<< lowestGrade[i]<< " position " // this is for testin purpose
<< lowPosition[i]<<" math " <<math[i][position]<<" position " <<position ; // same here
}
int main()
{
int math[ROWS][STUDENTS];
float averageGrade[ROWS];
int highestGrade[ROWS];
int lowestGrade[ROWS];
int indicator=0;
int lowPosition[ROWS];
int highLocation[ROWS];
int indexLow=0;
for (int i=0;i<ROWS;i++)
{
cout << "\n\n\tDigite la nota del examen de los alumnos de la hilera: " << i+1 <<" :\n";
for (int x=0;x<STUDENTS;x++)
{
cout << "\talumno "<< x+1 <<" : ";
cin >> math[i][x];
}
highest(math,highestGrade,highLocation,i);
lowest(math,lowestGrade,lowPosition,i);
}
return 0;
}
|