i made a simple program to take in two integers and evaluate their sum, product, etc... The problem is, Im wanting to display an error message if the user enters a character or a decimal number, but I have been unsuccessful achieving this. Please help!
here is my program:
Code:
#include <stdio.h>
int main(void)
{
int num1=0, num2=0;
int sum, diff1, diff2, product, quotient, average;
printf("Please enter the first integer:\n");
scanf("%d",&num1);
printf("Please enter the second integer:\n");
scanf("%d",&num2);
sum = num1 + num2;
diff1 = num1 - num2;
diff2 = num2 - num1;
product = num1*num2;
quotient = num1/num2;
average = (num1 + num2)/2;
if(num1 == num2)
{
printf("\nCONGRATULATIONS! The two integers you've entered are equal!\n\n");
}
printf("The sum of the integers is equal to:%d\n", sum);
printf("The difference of integer 1 minus integer 2 is equal to:%d\n",diff1);
printf("The difference of integer 2 minus integer 1 is equal to:%d\n",diff2);
printf("The product of the integers is equal to:%d\n",product);
printf("The quotient of the integers is equal to:%d\n",quotient);
printf("The average of the integers is equal to:%d\n", average);
return(0);
}