0
I am a beginner in programming and I have to assemble a code in which I put two values and the program gives me the result in sum, subtraction, multiplication and division, but when dividing a number by zero an error message appears. I was able to get an error message to appear if it is divided by zero, but I can’t do any other kind of division than zero. If anyone can enlighten me because I understand little yet of programming.
That is the code:
#include <stdio.h>
#include <stdlib.h>
int main()
{
int num1, num2, soma, subtracao, multiplicacao, divisao;
printf("Digite o primeiro numero:");
scanf_s("%d", &num1);
printf("Digite o segundo numero:");
scanf_s("%d", &num2);
soma = num1 + num2;
subtracao = num1 - num2;
multiplicacao = num1 * num2;
divisao = num1 / num2;
printf("A soma = %d\n", soma);
printf("\n");
printf("A subtracao = %d\n", subtracao);
printf("\n");
printf("A multiplicacao = %d\n", multiplicacao);
printf("\n");
printf("A divisao = %d\n", divisao);
if (num2 != 0)
divisao = num1 / num2;
else
printf("Invalido, nao pode ser divido por 0");
printf("\n");
system("pause");
return 0;
}
This ain’t C#, man. It most probably ain’t got nothing to do with dynamic programming either.
– Jéf Bueno