I am a bit stuck on a code i am writing right now. I need to check a double number, if the digit after the comma is two. My code always tells me, that there a too much.
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
//Code by Ninto
int main(){
double numbers[25] = {0.0};
int twoOnDecile = 0;
srand(time(NULL));
for(int i = 0;i <= 24;i++){
numbers[i] = (double)rand()/RAND_MAX*64-32;
if(i % 8 == 0)printf("\n");
else printf(";");
printf("%7.2lf",numbers[i]);
if((numbers[i]-(int)numbers[i])/2.0 >= 0.1&&(numbers[i]-(int)numbers[i])/2.0 < 0.4)twoOnDecile++;
if((numbers[i]-(int)numbers[i])*-1/2.0 >= 0.1&&(numbers[i]-(int)numbers[i])*-1/2.0 < 0.4)twoOnDecile++;
}
printf("\n2 on decile rank:%d",twoOnDecile);
return 0;
}