i cant figure out this if statment
It is driving me nuts
all im trying to do is take in for floats
evaluate them and print which one is bigger
im very new to C
for some reason the first half works but the second half doesnt
For some reason the bottom part that says print integer is passing its criteria and keeps printing integer 2 out when integer 2 clearly is not less the integer 1
im just giving it the input "1 2 3 4 "
can someone please tell me why when given "1 2 3 4" it thinks my else if for integer 2 is true and is printing
It is clearly false. I used && gates so all factors must be true for it to print. obviously it fails so why and how could it be printing
Code:#include <stdio.h> #include <stdlib.h> int main() { float integer_1;//first number float integer_2;//second number float integer_3;//3rd number float integer_4;//4th number printf("this program displays the largest and smallest number entered by the user"); printf("Please enter the 4 integers you would like to use with a space between them xx xx xx xx"); scanf("%f %f %f %f",&integer_1 ,&integer_2 ,&integer_3 ,&integer_4);//store the value of user input // into the correct variable location printf("%.1f %.1f %.1f %.1f\n",integer_1,integer_2,integer_3,integer_4);// print the variable on the screen to confirm they are taken in correctly. Just for testing if (integer_1>integer_2&&integer_1>integer_3&&integer_1>integer_4)//logical system to answer the question is integer 1 the biggest. If it does not pass to any of the criteria is should move on to next line printf("Largest%f\n",integer_1);//if it pass print largest value else if (integer_1<integer_2&&integer_1<integer_3&&integer_1<integer_4);//test to see if integer 1 is possibly the smallet value printf("smallest %.1f\n",integer_1);//if it is print it on the screen printf("%.2f %.2f %.2f %.2f\n\n\n",integer_1,integer_2,integer_3,integer_4);//just for testing if ((integer_2>integer_1)&&(integer_2>integer_3)&&(integer_2>integer_4))//logical system to find out if integer 2 is the greatest value printf("Largest%f\n",integer_2);//if it is print it else if (integer_2<integer_1&&integer_2<integer_3&&integer_2<integer_4);//logical system to see if integer 2 is smallest, if it is print it. If no criteria is met move on. {printf("smallest %.1f\n",integer_2);}//this one is the problem i speak of! it keeps printing this off when its FALSE return(0); }



LinkBack URL
About LinkBacks




