Hi i am writing a series of if statements that determine which set of coordinates is the has the max value.
I have a formula that calculates the max value of z and by using coordinates of (x,y). Ie z= (2*y)+x
that works well. I then need to be able to get it so that the program tells me which set of coordinates it used to get that z value. (there are 3 pairs of coordinates).
The coordinates are given to us and i just want the max coordinates to be called a new variable.
I haven't included the whole code as its very long as I'm doing other stuff there as well but i think i gave all the info needed...
The program has already calculated z0, z1,z2, max successfully
Coordinates are defined like this at the start:
double P0 [] = {7,8};
double P1 [] = {2,4};
double P2 [] = {3,2};
I just need max to contain the array of the coordinates that give me the value for zmax.
Thanks!!
What I have tried:
if (zmax==z0){
max=P0[];
} else if (zmax==z1){
max=P1[];
} else {
max=P2[];
}
printf("ph is %f/n",max[0],max[1]);
NEW VERSION:
float maxformula (float z0, float z1, float z2, float zmax,float P0[], float P1[], float P2[]);
float maxformula (float z0, float z1, float z2, float zmax,float P0[], float P1[], float P2[]){
if (zmax==z0){
printf("zmax is zo");
double max[]={P0[0],P0[1]};
printf("max is %f %f\n", max[0],max[1]);
} else if (zmax==z1){
printf("zmax is z1\n");
double max[]={P1[0],P1[1]};
printf("max is %f %f\n", max[0],max[1]);
} else if (zmax==z2){
printf("zmax is z2");
double max[]={P2[0],P2[1]};
printf("max is %f %f\n", max[0],max[1]);
}
}
In the main:
maxformula(z0,z1,z2,zmax,P0,P1,P2);
For some reason gives me the correct values but the x and y are flipped (so the max[0] is the y max[1] is the x