So Im writing up a program that will take in 4 inputs and then using ONLY if statements ,comapre them and return the minimum value
#include <stdio.h>
int main(void) {
double w, x, y, z;
double min; /* the variable to hold the minimum value */
/* Do not change the following input statement */
scanf("%lf%lf%lf%lf", &w,&x,&y,&z);
/* Enter your solution here */
if ( w > x && y && z ){
min = w;
}
else if ( x > w && y && z ){
min = x;
}
else if ( y > w && x && z ){
min = y;
}
else if ( z > w && x && y ){
min = z;
}
else {
printf("Huh?! 0_0");
}
/* Do not change the following output statement */
printf("%f\n",min);
return 0;
}
In my if statment above im trying to compare one input at a time to the other 3, but in the instance that the inputs are 1,2,3,4 respectively the second value(2) is printed when 4 should be the output.
Could anyone tell me what exactly is wrong with my code? Any help would be appreciated, thanks :))
P.s. I know I can use arrays and other methods to solve this problem but I'm new to C Porgramming so I'm only trying to use if statements for now
Aucun commentaire:
Enregistrer un commentaire