-
Is this right?
I am writing this program for some extra credit, but it seems entirely too easy, and I have no way of checking it because my compiler doesn't like getchar.
The program is just supposed to add 4 to an integer if a float is greater than 5.4.
Code:
#include <stdio.h>
#include <math.h>
int main()
{
int num;
float amount;
printf("Please enter a number: ");
if (amount > 5.4)
num = num + 4;
return 0;
}
Also, I am supposed to write another program for extra credit but I don't understand what it means exactly. It says, "Write the code to print either zero or not zero based on the integer variable num."
These programs are only worth 1 point each (out of 1000 for the whole course) so I am not going to greatly alter my grade by doing these, so I figured it wouldn't matter if I asked for some help (policy of not doing people's HW).
TIA
-
comparing floating point number wouldn't give u the right result. Thats because the way the computer handles floating point is different and complicated. Google on how to compare floating point number. You will get tons of links.
ssharish
-
It seems you forgot to add a statement (after the printf) to accept the user input for the float value