October 22, 2024
Chicago 12, Melborne City, USA
C++

Casting in C – confused


I have a tiny little code snipplet here:

#include <stdio.h>
#include <math.h> 
void main(void)


{
int clouds=15;
double  
    Zenith_rad=1.1827,
    Normal_direct=774.6839,
    A=0, B=0, C=0;      

A = Normal_direct * cos(Zenith_rad);
B = A * ( 1 - ( clouds / 100)) ;
C = A * ( 1 - ( 0.15)) ;
printf("A: %f\n" ,A);
printf("B: %f\n" ,B);
printf("C: %f\n" ,C);
}

Expected result:

A: 293.161306
B: 249.187110
C: 249.187110

Seen result:

A: 293.161306
B: 293.161306
C: 249.187110

Adding a (double) cast in front of clouds makes it working.
Why?

Thanks!

/KNEBB



You need to sign in to view this answers

Leave feedback about this

  • Quality
  • Price
  • Service

PROS

+
Add Field

CONS

+
Add Field
Choose Image
Choose Video