What is the best method of setting speed, temp & altitude to imperial units?
Thanks!
Jason
What is the best method of setting speed, temp & altitude to imperial units?
Thanks!
Jason
Hi,
I guess that you can use the Macros
here is some example: tested on onlinegdb
UPDATE: cleaner version with demonstration how to use integer values and float
/******************************************************************************
Online C Compiler.
Code, Compile, Run and Debug C program online.
Write your code in this editor and press "Run" button to compile and execute it.
*******************************************************************************/
#include <stdio.h>
#define FT_TO_M(x) (((float)(x)*(0.3048)))
#define M_TO_FT(x) (((float)(x)/(0.3048)))
#define KMH_TO_MPH(x) ((x)/( 1.609344))
#define DEGC_TO_DEGF(x) ((x)*(9.0/5.0)+32.0)
int speed_km = 120;
int distance_f = 33;
float altitude_m = 1100.0;
float temp_c = 23.0;
int main()
{
printf("speed[kmh] is: %d ",speed_km);
printf("and speed[mph] is: %.2f \n",KMH_TO_MPH(speed_km));
printf("distance[ft] is: %d ",distance_f);
printf("and distance[m] is: %.2f \n",FT_TO_M(distance_f));
printf("altitude[m] is: %.2f ",altitude_m);
printf("and altitude[ft] is: %.2f \n",M_TO_FT(altitude_m));
printf("temp[c] is: %.2f ",temp_c);
printf("and temp[f] is: %.2f \n",DEGC_TO_DEGF(temp_c));
return 0;
}
and results: