Floating poing if statment
Go to solution
Solved by mariushm,
You got the order wrong, the
printf(" y is less than 10");
should be at the lowest if ...
edit: and yeah, use the correct data type... float for floating point numbers
also, I think you'd want to use >= in some places, because for example, in your code, if y is between 10.000 and 11, the number won't be tested.
You could also use a FOR loop instead of ifs for this ... something like this:
int counter; int min; int max; for ( counter = 0;counter<6;counter++ ) { min = counter * 10; max = (counter+1) * 10; if (y>=min && y<max) { // syntax may be wrong here but you should get the point printf("y is equal or greater than %d and smaller than %d",min,max); } }
or you could calculate the remainder of the division of y by 10, substract it, then divide by 10 ... something like this.
int remainder; int value; value = y; remainder = value % 10; value = (value-remainder) / 10; printf("y is equal or larger than %d and smaller than %d", value*10, (value+1)*10);
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now