by pressing enter, cmd opens but closes even not completing all commands

Asked

Viewed 154 times

0

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

int main (void)

{
    int valor1,valor2,soma,sub,mult,di;


    printf("Digite um numero inteiro: ");
    scanf("%d\n",valor1);

    printf("Digite outro numero inteiro: ");
    scanf("%d\n",valor2);

    soma = valor1 + valor2;
    sub = valor1 - valor2;
    mult = valor1 * valor2;
    di = valor1 / valor2; 

    printf("Valor da soma de %d + %d = %d\n",valor1,valor2,soma);
    printf("Valor da subtracao de %d + %d = $d\n",valor1,valor2,sub);
    printf("Valor da multiplicacao de %d * %d = %d\n",valor1,valor2,mult);
    printf("Valor da divisão de %d / %d = %d\n",valor1,valor2,di);


    system("PAUSE");
    return 0;

}

my command is like this, but every time I run, it takes only the first number and simply closes(Obs: I’m new to programming) inserir a descrição da imagem aqui

1 answer

1

You are forgetting to use the '&' in the scanf...

..., &valor1) ...
..., &valor2) ...

ps: also has a wrong formatting in your second printf(), just replace the char $ by %.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.