2
Hi, I’m coming back to the C language after a while. I’ve always used Code :: Blocks, but now, I migrated to Vscode. When I try to print values, giant numbers come out, for example: n°1 = 15 and n°2 = 5. When I print out, a number like: 15674213 comes out. Sorry if the text came out weird. It’s my first time here!
#include <stdio.h>
#include <stdlib.h>
int main(){
    //Variaveis
    int num1, num2, soma, subtracao, multiplicacao, divisao;
            soma                   = num1 + num2;
            subtracao              = num1 - num2;
            multiplicacao          = num1 * num2;
            divisao                = num1 / num2;
    //Mensagens
    printf("CALCULADORA 0.1\n");
    printf("A nossa calculadora, realiza calculos com apenas dois números.\n");
    //Coletar primeiro numero
    printf("Digite o primeiro número:");
    scanf("%i", &num1);
    //Coletar segundo numero
    printf("Digite o segundo número:");
    scanf("%i", &num2);
    //Imprimir resultados
    printf("Valor da soma: %i\n", soma);
    printf("Valor da subtração: %i\n", subtracao);
    printf("Valor da multiplicação: %i\n",multiplicacao);
    printf("Valor da divisão: %i\n", divisao);
    //Manter execucao
    return 0;
}
						
If this is the order of the commands in your code then the problem is that you are doing the operations before to read the values to be used in such operations.
– anonimo
If you are using gcc use the -Wall option, and then show that these variables were used without initializing.
– Pedro
Thank you! You helped a lot here!
– Lorran Rocha