1. ## maximum number

Ok fellas check it out I've managed to get most of the code working except for the maximum function it keeps returning a
value of 0. What do you guys think the problem could be

Code:
```#include <stdio.h>
#include <math.h>

int maximum();
int main()

{
int val[3][4],val2[3][4], val3[3][4], controlnum;

printf("what kind of operation will you be performing\n");
printf(" (2 for multiplication)\n");
printf(" (3 for division )\n");
printf(" (4 for transposing)\n");
printf(" (5 for maximum number)\n");
scanf("%d", &controlnum);
printf("\nEnter your set of values ");
scanf("%2d %2d %2d %2d %2d %2d %2d %2d %2d %2d %2d %2d",
&val[0][0],&val[0][1],&val[0][2],&val[0][3],
&val[1][0],&val[1][1],&val[1][2],&val[1][3],
&val[2][0],&val[2][1],&val[2][2],&val[2][3]);

printf("\nYour first set of values is\n");
printf("_____________");
printf("\n|%2d %2d %2d %2d|\n",	val[0][0], val[0][1], val[0][2], val[0][3]);
printf("\n|%2d %2d %2d %2d|\n",	val[1][0], val[1][1], val[1][2], val[1][3]);
printf("\n|%2d %2d %2d %2d|\n",	val[2][0], val[2][1], val[2][2], val[2][3]);
printf("_____________");

printf("\nEnter another set of values\n");

scanf("%2d %2d %2d %2d %2d %2d %2d %2d %2d %2d %2d %2d",
&val2[0][0],&val2[0][1],&val2[0][2],&val2[0][3],
&val2[1][0],&val2[1][1],&val2[1][2],&val2[1][3],
&val2[2][0],&val2[2][1],&val2[2][2],&val2[2][3]);
printf("\nYour second set of values is\n");
printf("____________");
printf("\n|%2d %2d %2d %2d|\n",	val2[0][0], val2[0][1], val2[0][2], val2[0][3]);
printf("\n|%2d %2d %2d %2d|\n",	val2[1][0], val2[1][1], val2[1][2], val2[1][3]);
printf("\n|%2d %2d %2d %2d|\n",	val2[2][0], val2[2][1], val2[2][2], val2[2][3]);
printf("____________\n");

if (controlnum == 1)

{
printf("\n%2d %2d %2d %2d\n",
val3[0][0] = val[0][0] + val2[0][0],
val3[0][1] = val[0][1] + val2[0][1],
val3[0][2] = val[0][2] + val2[0][2],
val3[0][3] = val[0][3] + val2[0][3]);

printf("\n%2d %2d %2d %2d\n",
val3[1][0] = val[1][0] + val2[1][0],
val3[1][1] = val[1][1] + val2[1][1],
val3[1][2] = val[1][2] + val2[1][2],
val3[1][3] = val[1][3] + val2[1][3]);

printf("\n%2d %2d %2d %2d\n",
val3[2][0] = val[2][0] + val2[2][0],
val3[2][1] = val[2][1] + val2[2][1],
val3[2][2] = val[2][2] + val2[2][2],
val3[2][3] = val[2][3] + val2[2][3]);
}
else if(controlnum == 2)
{
printf("\n%2d %2d %2d %2d\n",
val3[0][0] = val[0][0] * val2[0][0],
val3[0][1] = val[0][1] * val2[0][1],
val3[0][2] = val[0][2] * val2[0][2],
val3[0][3] = val[0][3] * val2[0][3]);

printf("\n%2d %2d %2d %2d\n",
val3[1][0] = val[1][0] * val2[1][0],
val3[1][1] = val[1][1] * val2[1][1],
val3[1][2] = val[1][2] * val2[1][2],
val3[1][3] = val[1][3] * val2[1][3]);

printf("\n%2d %2d %2d %2d\n",
val3[2][0] = val[2][0] * val2[2][0],
val3[2][1] = val[2][1] * val2[2][1],
val3[2][2] = val[2][2] * val2[2][2],
val3[2][3] = val[2][3] * val2[2][3]);
}
else if(controlnum == 3)
{
printf("\n%2d %2d %2d %2d\n",
val3[0][0] = val[0][0] / val2[0][0],
val3[0][1] = val[0][1] / val2[0][1],
val3[0][2] = val[0][2] / val2[0][2],
val3[0][3] = val[0][3] / val2[0][3]);

printf("\n%2d %2d %2d %2d\n",
val3[1][0] = val[1][0] / val2[1][0],
val3[1][1] = val[1][1] / val2[1][1],
val3[1][2] = val[1][2] / val2[1][2],
val3[1][3] = val[1][3] / val2[1][3]);

printf("\n%2d %2d %2d %2d\n",
val3[2][0] = val[2][0] / val2[2][0],
val3[2][1] = val[2][1] / val2[2][1],
val3[2][2] = val[2][2] / val2[2][2],
val3[2][3] = val[2][3] / val2[2][3]);
}
else if(controlnum == 4)
{

printf("\n%2d %2d %2d %2d\n",
val3[0][0]= val2[0][0],
val3[0][1]= val2[0][1],
val3[0][2]= val2[0][2],
val3[0][3]= val2[0][3]);

printf("\n%2d %2d %2d %2d\n",
val3[1][0]= val2[0][0],
val3[1][1]= val2[1][1],
val3[1][2]= val2[1][2],
val3[1][3]= val2[1][3]);

printf("\n%2d %2d %2d %2d\n",
val3[2][0]= val2[2][0],
val3[2][1]= val2[2][1],
val3[2][2]= val2[2][2],
val3[2][3]= val2[2][3]);

printf("\n%2d %2d %2d %2d\n",
val3[0][0]= val[0][0],
val3[0][1]= val[0][1],
val3[0][2]= val[0][2],
val3[0][3]= val[0][3]);

printf("\n%2d %2d %2d %2d\n",
val3[1][0]= val[0][0],
val3[1][1]= val[1][1],
val3[1][2]= val[1][2],
val3[1][3]= val[1][3]);

printf("\n%2d %2d %2d %2d\n",
val3[2][0]= val[2][0],
val3[2][1]= val[2][1],
val3[2][2]= val[2][2],
val3[2][3]= val[2][3]);
}
else if (controlnum== 5)
maximum();
{
maximum();
}

return 0;
}
int maximum()
{
int maxnum,  val[3][4], val2[3][4];

maxnum = 0;
if (val[0][0] >= maxnum)
val[0][0] = maxnum;
else if (val[0][1] >= maxnum)
val[0][1] = maxnum;
else if (val[0][2] >= maxnum)
val[0][2] = maxnum;
else if (val[0][3] >= maxnum)
val[0][3] = maxnum;
else if (val[1][1] >= maxnum)
val[1][1] = maxnum;
else if (val[1][2] >= maxnum)
val[1][2] = maxnum;
else if (val[1][3] >= maxnum)
val[1][3] = maxnum;
else if (val[2][1] >= maxnum)
val[2][1] = maxnum;
else if (val[2][2] >= maxnum)
val[2][2] =maxnum;
else if (val[2][3] >= maxnum)
val[2][3] = maxnum;
else if (val[0][0] >= maxnum)
val[0][0] = maxnum;
else if (val[0][1] >= maxnum)
val[0][1] = maxnum;
else if (val[0][2] >= maxnum)
val[0][2] = maxnum;
else if (val[0][3] >= maxnum)
val[0][3] = maxnum;
else if (val[1][1] >= maxnum)
val[1][1] = maxnum;
else if (val[1][2] >= maxnum)
val[1][2] = maxnum;
else if (val[1][3] >= maxnum)
val[1][3] = maxnum;
else if (val[2][1] >= maxnum)
val[2][1] = maxnum;
else if (val[2][2] >= maxnum)
val[2][2] =maxnum;
else if (val[2][3] >= maxnum)
val[2][3] = maxnum;

printf("the maximum number is %d\n", maxnum);
return 0;
}```

2. maxnum = 0;

if (val[0][0] >= maxnum)
val[0][0] = maxnum;
else if (val[0][1] >= maxnum)

I'd use a loop for this stuff instead of this if else structure.

Do you intend to set all these elements to 0 if val[][] >= 0?

Do you want

maxnum = val[][] ?

3. ## for loops

I did try the for loop structure originally but I decided to use the if else structure to make the code more logical to me i.e. (didn't have time for a deskcheck). So I used the if else structure instead no matter which way I do it I always come out with a 0 as my maximum number. It is not my intention to set all of the values to 0. The goal is to compare the numbers in each field of both arrays and obtain the maximum number in both arrays. So if val[0][0] is greater than maxnum, val[0][0] is equal to maxnum and so on.

4. i.e. (didn't have time for a deskcheck).
One law of projects: "There is never enough time to do it right the first time, but always enough time to do it over" ;-)

The loop idea will be *much* easier to read and debug.

Ronin is right, you start Maxnum at zero then load that zero into the array value instead of loading the array value into Maxnum.

5. And you're comparing to random data.
Code:
```int maximum()
{
int maxnum,  val[3][4], val2[3][4]; /* unitialized data */

maxnum = 0;
if (val[0][0] >= maxnum)
val[0][0] = maxnum;
/* ... */```

6. Originally posted by drdodirty2002
I did try the for loop structure originally but I decided to use the if else structure to make the code more logical to me i.e. (didn't have time for a deskcheck). So I used the if else structure instead no matter which way I do it I always come out with a 0 as my maximum number. It is not my intention to set all of the values to 0. The goal is to compare the numbers in each field of both arrays and obtain the maximum number in both arrays. So if val[0][0] is greater than maxnum, val[0][0] is equal to maxnum and so on.
Someone posted (I guess he / she deleted it) prior to my first reply that it's always 0 because your function is returning 0... true enough. I wasn't sure if you intended to just print the highest and then return 0.

Not the most proficient code, but perhaps it will help you come up with something.

Code:
```#include <stdio.h>

#define MAXROW 3
#define MAXCOL 3

int largest(int array[MAXROW][MAXCOL])
{
/* not my memory so waste it with a copy :P */

int largest = array[0][0];
int i, j;

for(i=0; i < MAXROW; i++)
{
for(j=0; j < MAXCOL; j++)
if(largest < array[i][j])
largest = array[i][j];
}

return largest;
}

int main()
{
int myarray[MAXROW][MAXCOL] = { { 12, 35, 2  },
{ 76, 16, 33 },
{ 55, 11, 41 } };

printf("largest value in myarray = %d", largest(myarray));

return 0;
}```
HTH

7. ## heres what I got

Here is what I've managed to come up with

Code:
```#include <stdio.h>
#include <math.h>

int getmaxnum(int,int);
int main()

{
int val[3][4],val2[3][4], val3[3][4], controlnum,maxnum, minnum;

printf("what kind of operation will you be performing\n");
printf(" (2 for multiplication)\n");
printf(" (3 for division )\n");
printf(" (4 for transposing)\n");
printf(" (5 for maximum number)\n");
scanf("%d", &controlnum);
printf("\nEnter your set of values ");
scanf("%2d %2d %2d %2d %2d %2d %2d %2d %2d %2d %2d %2d",
&val[0][0],&val[0][1],&val[0][2],&val[0][3],
&val[1][0],&val[1][1],&val[1][2],&val[1][3],
&val[2][0],&val[2][1],&val[2][2],&val[2][3]);

printf("\nYour first set of values is\n");
printf("_____________");
printf("\n|%2d %2d %2d %2d|\n",	val[0][0], val[0][1], val[0][2], val[0][3]);
printf("\n|%2d %2d %2d %2d|\n",	val[1][0], val[1][1], val[1][2], val[1][3]);
printf("\n|%2d %2d %2d %2d|\n",	val[2][0], val[2][1], val[2][2], val[2][3]);
printf("_____________");

printf("\nEnter another set of values\n");

scanf("%2d %2d %2d %2d %2d %2d %2d %2d %2d %2d %2d %2d",
&val2[0][0],&val2[0][1],&val2[0][2],&val2[0][3],
&val2[1][0],&val2[1][1],&val2[1][2],&val2[1][3],
&val2[2][0],&val2[2][1],&val2[2][2],&val2[2][3]);
printf("\nYour second set of values is\n");
printf("____________");
printf("\n|%2d %2d %2d %2d|\n",	val2[0][0], val2[0][1], val2[0][2], val2[0][3]);
printf("\n|%2d %2d %2d %2d|\n",	val2[1][0], val2[1][1], val2[1][2], val2[1][3]);
printf("\n|%2d %2d %2d %2d|\n",	val2[2][0], val2[2][1], val2[2][2], val2[2][3]);
printf("____________");

if (controlnum == 1)

{
printf("\n%2d %2d %2d %2d\n",
val3[0][0] = val[0][0] + val2[0][0],
val3[0][1] = val[0][1] + val2[0][1],
val3[0][2] = val[0][2] + val2[0][2],
val3[0][3] = val[0][3] + val2[0][3]);

printf("\n%2d %2d %2d %2d\n",
val3[1][0] = val[1][0] + val2[1][0],
val3[1][1] = val[1][1] + val2[1][1],
val3[1][2] = val[1][2] + val2[1][2],
val3[1][3] = val[1][3] + val2[1][3]);

printf("\n%2d %2d %2d %2d\n",
val3[2][0] = val[2][0] + val2[2][0],
val3[2][1] = val[2][1] + val2[2][1],
val3[2][2] = val[2][2] + val2[2][2],
val3[2][3] = val[2][3] + val2[2][3]);
}
else if(controlnum == 2)
{
printf("\n%2d %2d %2d %2d\n",
val3[0][0] = val[0][0] * val2[0][0],
val3[0][1] = val[0][1] * val2[0][1],
val3[0][2] = val[0][2] * val2[0][2],
val3[0][3] = val[0][3] * val2[0][3]);

printf("\n%2d %2d %2d %2d\n",
val3[1][0] = val[1][0] * val2[1][0],
val3[1][1] = val[1][1] * val2[1][1],
val3[1][2] = val[1][2] * val2[1][2],
val3[1][3] = val[1][3] * val2[1][3]);

printf("\n%2d %2d %2d %2d\n",
val3[2][0] = val[2][0] * val2[2][0],
val3[2][1] = val[2][1] * val2[2][1],
val3[2][2] = val[2][2] * val2[2][2],
val3[2][3] = val[2][3] * val2[2][3]);
}
else if(controlnum == 3)
{
printf("\n%2d %2d %2d %2d\n",
val3[0][0] = val[0][0] / val2[0][0],
val3[0][1] = val[0][1] / val2[0][1],
val3[0][2] = val[0][2] / val2[0][2],
val3[0][3] = val[0][3] / val2[0][3]);

printf("\n%2d %2d %2d %2d\n",
val3[1][0] = val[1][0] / val2[1][0],
val3[1][1] = val[1][1] / val2[1][1],
val3[1][2] = val[1][2] / val2[1][2],
val3[1][3] = val[1][3] / val2[1][3]);

printf("\n%2d %2d %2d %2d\n",
val3[2][0] = val[2][0] / val2[2][0],
val3[2][1] = val[2][1] / val2[2][1],
val3[2][2] = val[2][2] / val2[2][2],
val3[2][3] = val[2][3] / val2[2][3]);
}
else if(controlnum == 4)
{

printf("\n%2d %2d %2d %2d\n",
val3[0][0]= val2[0][0],
val3[0][1]= val2[0][1],
val3[0][2]= val2[0][2],
val3[0][3]= val2[0][3]);

printf("\n%2d %2d %2d %2d\n",
val3[1][0]= val2[0][0],
val3[1][1]= val2[1][1],
val3[1][2]= val2[1][2],
val3[1][3]= val2[1][3]);

printf("\n%2d %2d %2d %2d\n",
val3[2][0]= val2[2][0],
val3[2][1]= val2[2][1],
val3[2][2]= val2[2][2],
val3[2][3]= val2[2][3]);

printf("\n%2d %2d %2d %2d\n",
val3[0][0]= val[0][0],
val3[0][1]= val[0][1],
val3[0][2]= val[0][2],
val3[0][3]= val[0][3]);

printf("\n%2d %2d %2d %2d\n",
val3[1][0]= val[0][0],
val3[1][1]= val[1][1],
val3[1][2]= val[1][2],
val3[1][3]= val[1][3]);

printf("\n%2d %2d %2d %2d\n",
val3[2][0]= val[2][0],
val3[2][1]= val[2][1],
val3[2][2]= val[2][2],
val3[2][3]= val[2][3]);
}
else if (controlnum == 5)
{

printf("\nmaxnum is %d\n",maxnum);
}
int getmaxnum(int val[3][4], int val2[3][4]);
{
int i, j, val[3][4], val2[3][4];
maxnum =0;
for (i=0; i<=3; ++i)
{
for(j=0; j<=3;++j)
{
if (val[i][j] > maxnum)
val[i][j] = maxnum;
}
}
}
return (maxnum);
}```

8. Here is what I've managed to come up with
And? Are you having problems still or what? You can't just expect people to read 500 lines of code, or to grab it all and try and make it compile with no explanation of what it's currently doing or not doing.

If you want people to help you, it's your job to provide as much information as possible so they can do so.

Quzah.