# Thread: Help with if statement

1. ## Help with if statement

This is an assignment i'm working on:
Write a C program that indicates which of the two given numbers is greater. The program
should receive two float numbers as input from the user. If the first number is greater, the output
should be “The greater number is 1” otherwise the output should be “The greater
number is 2”. Save your program in a file called p3.c. If they are equal, the output should be "The greater number is 1".
Code:
``` #include <stdio.h>
int main(void)
{
float a, b;
printf("Enter Number 1: ");
scanf("&#37;f", &a);
printf("Enter Number 2: ");
scanf("%f", &b);

if (a > b)
printf("The Greater Number is 1");
else if (a == b)
printf("The Greater Number is 1");
else
printf("The Greater Number is 2");

return 0;
}```
Can someone help me out with this? When I run the program I choose two numbers and regardless of the numbers it prints The Greater Number is 1.

2. it seems to work for me. what 2 numbers are you trying that doesnt work?

3. i tried a= 2 and b= 3. i've tried multiple conditions where b is bigger or c is equal, but i always get "The Greater Number is 1"

4. It works properly for me also. There is probably a difference between what you are actually using and what you posted. BTW, you can combine "a > b" and "a == b" into a single condition "a >= b".

5. 2 and 3 work.. it seems to work completely for me. if your using an IDE, make sure to save the project, restart the program, recompile it and run it. if your using command line make sure your entering the proper commands and executing the most recently compiled program.

6. Oh, I had put in &a again for the second scanf instead of &b. Now it works. Thanks for the help guys.