Avatar of meguel Moses
meguel Moses
 asked on

what about c++ its giving me issues

I had this question after viewing 2d array Grade Book.
int  minimum (int  scores[4] [3])
{

    int  min, i,j;
min = scores[0][0];

for ( i = 0;  i<4;  ++i )
for (j=0; j<3; ++j)
if ( scores[i][j] < min )
min= scores[i][j];
return min;

}

//function for Maximum Value
int maximum (int values[4][3])
{
int  max, i,j;

max = values[0][0];

for ( i = 0;  i<4;  ++i )
  for (j=0; j<3; ++j)
if ( values[i][j] > max )
max= values[i][j];
return max;

}

//function for Average
float average (int values[4][3])
{float  sum=0.0;
int count=0;
float Average;
int i,j;

for(i=0;i<4;++i)
  for(j=0;j<3;++j)
{
sum=sum+values[i][j];
++count;
}
Average=sum/count;
return Average;
}
//function to find student average
float studentavg (int values[4][3])

float finalmark;

finalmark=values[0][0];
{

for ( j=0;i<3;++j){

  for(  i=0;i<4;++i){
  
 int rowsum=rowsum+values[i][j];

finalmark=rowsum/3;
printf("Student's final mark is %.2f\n", finalmark);
}

}


//Main Program
int main (void)
{
	int  values[4][3], i,j,min,max,sum=0,count=0;
	float Average,finalmark;
	int rowsum=0;
int  minimum (int  values[4][3]);
int maximum (int values[4][3]);
float average (int values[4][3]);
float studentavg (int values[4][3]);


printf ("Enter Values: \n");
	for ( i = 0; i< 4; i++ ) {

      for ( j = 0; j< 3; j++ ) {
         printf(" values[%i][%i] = ", i,j, values[i][j] );
         scanf("%i", &values[i][j]);
      }
   }
   printf("\n");
   printf("\n");
   printf("\n");      


min = minimum(values);
max = maximum(values);
Average = average(values);
finalmark=studentavg(values);


printf(" The minimum value is %i\n", min);
printf(" The maximum value is %i\n", max);
printf (" The Class final mark is %.2f\n", Average);


return 0;
}

    }
    
}

Open in new window

C++

Avatar of undefined
Last Comment
meguel Moses

8/22/2022 - Mon
Subrat (C++ windows/Linux)

what issue you are getting.

int rowsum=rowsum+values[i][j]; is dangerous. bcz in each iteration of inner for loop, new variable is generating.
You need the declaration of
rowsum out side the inner for loop and initialize it to 0.
Subrat (C++ windows/Linux)

pls ignore the above comment.

pls tell what issue you are getting.
ASKER CERTIFIED SOLUTION
phoffric

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
meguel Moses

ASKER
thanks very much it worked just have to change the output a little again, was my first time using it was helping out a friend, i get mixed with java.
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck