0
#include<stdio.h>

int main(void)
{
    //declare and initialize variables.//
    double dollars = 0;
    double exchange_rate = 0;
    double shekels = 0;
    
    //get input from user.//
    scanf("%f %f", &dollars, &exchange_rate);
    
    // calculate sum.//
    shekels = exchange_rate * dollars;
    
    // print result.//
    printf("%f", shekels);
    
    return 0;
}

I keep getting zeros no matter what two numbers I put in . It always has been the case for me when using doubles so I want to understand what I'm doing wrong here. When can I use double and how can I use it?

joan
  • 21
  • 2
  • [Always enable compiler warnings and read them](https://stackoverflow.com/q/57842756/995714) – phuclv Sep 25 '22 at 12:44
  • 1
    Never use floating-point numbers for money. Floating point arithmetic will lead to rounding errors, and give you wrong results. Instead deal with the smallest denominator of the currency, like cents, and when needed display it using integer operations to get the dollars and cents separate. – Some programmer dude Sep 25 '22 at 12:45

0 Answers0