Trying to generate a list of temperatures that increment by 0.2 degrees in even numbers. The first temperature in the list is the result of a separate function not shown. Always a float but could be even or odd.
The objective is to:
Trim the first generated temperature to one digit after the decimal point.
Test to see if even or odd.
If even, add 0.2 until temp reaches 100
If odd add 0.1 to get to even, then 0.2 thereafter up to 100 (boiling poing water C)
So in the example the list would become 71.72, 71.8, 72.0, 72.2..., 100.0
The compiler clearly does not allow the modulo operand with float and int types. And the code seems clumsy to me.
Advice?
Thank you
The objective is to:
Trim the first generated temperature to one digit after the decimal point.
Test to see if even or odd.
If even, add 0.2 until temp reaches 100
If odd add 0.1 to get to even, then 0.2 thereafter up to 100 (boiling poing water C)
So in the example the list would become 71.72, 71.8, 72.0, 72.2..., 100.0
The compiler clearly does not allow the modulo operand with float and int types. And the code seems clumsy to me.
Advice?
Thank you
C:
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int main()
{
double temp1, temp2, temp3 = 0;
temp1 = 71.72;
temp2 = (temp1 - trunc(temp1));
temp3 = (round(temp2*10))/10;
if((temp2 + temp3) % 2 == 0){
temp2 = temp2 + temp3;
printf("\ntemp is even %lf", temp2);
}
else{
temp2 = temp2 + temp3 + 0.1;
printf("\ntemp is odd %lf", temp2);
}
int count = 1;
do{
temp2 += 0.2;
count++;
printf("\ncount = %d \ttemp = %.1lf", count, temp2);
} while (temp1 <= 100);
}