Error converting degrees Celsius to Farenheit C exercise [closed]

1

Convert celsius to grades fahrenheit

   #include <stdio.h>

    int main(){
        int g_c
        int g_f = 32; 
        int mult = 0;
        printf("Digite el numero de grados celsius: ");
        scanf("%i",&g_c,);
        mult = g_c * g_f;
        printf("La conversion es: %i",mult);
        return 0;
    }
    
asked by Joseph Garcia Aviles 25.09.2018 в 23:17
source

2 answers

0

You had some syntax errors and something wrong in the logic you must multiply the degrees celsius by 1.8 and then add 32 use this guide :

#include <stdio.h>

int main(){
    int g_c;
    int g_f = 32; 
    int mult = 0;
    printf("Digite el numero de grados celsius: ");
    scanf("%i",&g_c);
    mult = (g_c * 1.8) + g_f;
    printf("La conversion es: %i",mult);
    return 0;
}
    
answered by 25.09.2018 в 23:24
0

1) Remember that in C, all sentences end with a semicolon.

2) Also that the function scanf () that helps us request data through The keyboard has two arguments ( scanf("%codigoFormato", &nombreVariableQueAlmacenaLaEntrada); ) and not 3 as you are doing (the arguments that use the functions are separated by ","):

#include <stdio.h>

    int main(){ 
        int g_c       //*ERROR 1)
        int g_f = 32; 
        int mult = 0;
        printf("Digite el numero de grados celsius: ");
        scanf("%i",&g_c,); //*ERROR 2)
        mult = g_c * g_f;
        printf("La conversion es: %i",mult);
        return 0;
    }

3) Now the formula for converting from Celsius to Farenheit is:

°F = °C × 9/5 + 32

Therefore the input value must be multiplied by 9/5 and add the variable that has the value of 32 ( g_f ):

mult = (g_c * 9/5) + g_f;    

Make these changes to make your program work correctly:

#include <stdio.h>

    int main() {
        int g_c;
            int g_f = 32; //* 1)
            int mult = 0;

            printf("Digite el numero de grados celsius: ");
            scanf("%i",&g_c); //* 2)

            mult = (g_c * 9/5) + g_f; //* 3)    
            printf("La conversion es: %i",mult);

            return 0;
    }
    
answered by 25.09.2018 в 23:30