jak scanf'em odczytac double?

0

Witam
Mój problem polega na tym że w poniższym programie wychodzą mi złe wyniki. Jeżeli wszystkie zmienne zamienię na typ float wyniki wychodzą dobre. Próbuje napisać program który działa na typach double.
Mój system to Vista 64 bit, a program to Dev-C++ 4.9.9.2. Dodam jeszcze że typ float na moim systemie ma 32 a double 64 bity. Proszę o pomoc w rozwiązaniu problemu.

#include <stdio.h>
#include <stdlib.h>

void temperatura(double n);

int main(void)
{
    double temp;
    printf("Podaj temperature w Fahrenheitach (k - koniec): ");
    while(scanf("%f", &temp)==1)
    {
                      temperatura(temp);
                      printf("Podaj temperature w Fahrenheitach (k - koniec): ");
    }
    
    system("pause");
    return 0;
}

void temperatura(double n)
{
     const float x = 32.0;
     const float y = 273.16;
     double cel, kel;
     cel=1.8 * n + x;
     kel = cel + y;
     
     printf("%.2f Fahrenheita to %.2f Celciusza, %.2f Kelwina\n", n, cel, kel);
}
0

%lf jest dla duble, %f dla float.
Należy czytać dokumentację ZANIM napisze sie na forum
http://www.cplusplus.com/reference/clibrary/cstdio/scanf/

1 użytkowników online, w tym zalogowanych: 0, gości: 1