1. ## Divide fail

Well ever other operator works instead of divide works. When I add multiply or subtract I get the correct results but when I divide I get some answer that aint numbers, works or even english.

Code:
```	else if(check == '/')
{
printf("Enter the first number.\n");
scanf("%d", &num1);
fflush(stdin);
printf("Enter the second number.\n");
scanf("%d", &num2);
fflush(stdin);

printf("The answer is: %f", num1 / num2);
}```

2. num1 and num2 are both integers so the result of the division is an int too. "%f" expects a float
Kurt

3. SourceForge.net: Fflush - cpwiki

It also might have something to do with your mixed use of integers (%d) and floats (%f).

num1 / num2 will be done in integer arithmetic, and won't be magically converted to float before trying to print it.

4. so If I added a variable and saved it in it would be printed as a float?

5. Originally Posted by BIGDENIRO
so If I added a variable and saved it in it would be printed as a float?
Paste your full code so we can highlight the mistake for you. As mentioned above, it may be due to the fflush or the way you have declared your variables.

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

int main()
{
int a = 6, b = 5;

printf("%f", a/b);

getchar();
return 0;

}```
I have declared a and b as int, but am trying to print a float. Do you have it something similar to the above?

6. Try printf("%f", (float)a / (float)b);

7. Originally Posted by rcgldr
Try printf("%f", (float)a / (float)b);
You don't have to explicitly promote both a and b

8. Originally Posted by bos1234
Paste your full code so we can highlight the mistake for you. As mentioned above, it may be due to the fflush or the way you have declared your variables.

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

int main()
{
int a = 6, b = 5;

printf("%f", a/b);

getchar();
return 0;

}```
I have declared a and b as int, but am trying to print a float. Do you have it something similar to the above?
look at the first post

9. Originally Posted by BIGDENIRO
look at the first post
And rc answered... try printf("%f\n", (float)a/b);

10. Originally Posted by rcgldr
Try printf("%f", (float)a / (float)b);
Originally Posted by SirPrattlepod
You don't have to explicitly promote both a and b
True, but it might help the original poster understand the issue better rather than relying on promotion of "b" to a float because "a" was cast to a float.

11. Originally Posted by rcgldr
True, but it might help the original poster understand the issue better rather than relying on promotion of "b" to a float because "a" was cast to a float.
You're really just being explicit, since the compiler will certainly have to promote both whether you write it that way or not.