/*Write a program that mimics a calculator. The program should take as input
two integers and the operation to be performed. It should then output the
numbers, the operator, and the result.(For division, if the denominator is
zero, output and appropriate message.) Some sample outputs follow:
3+4=7
13*5=65*/
#include <stdio.h>
int main()
{
int a,c;
char b;
printf("Input first integer: ");
scanf_s("%i", &a);
printf("What's the operation to be performed: ");
scanf_s("%s", &b);
printf("Input second integer: ");
scanf_s("%i", &c);
int A,B,C;
float D;
A = a + c;
B = a - c;
C = a * c;
D = a / c;
if (c == 0 && b == '/')
{
printf("The solution to the information given is : %i / %i = The denominator is zero and cannot be calculated\n\n", a,c);
}
else if (b == '-')
{
printf("The solution to the information given is : %i - %i = %i\n\n", a,c,B);
}
else if (b == '*')
{
printf("The solution to the information given is : %i * %i = %i\n\n", a,c,C);
}
else if (b == '/')
{
printf("The solution to the information given is : %i / % = %.2f\n\n", a,c,D);
}
else
{
printf("The solution to the information given is : %i + %i = %i\n\n", a,c,A);
}
#include <stdio.h>
int main()
{
int a,c;
char b;
printf("Input first integer: ");
scanf("%i", &a);
getchar();
printf("What's the operation to be performed: ");
scanf("%c", &b);
getchar();
printf("Input second integer: ");
scanf("%i", &c);
getchar();
if (c == 0 && b == '/')
{
printf("The solution to the information given is : %i / %i = The denominator is zero and cannot be calculated\n\n", a,c);
}
elseif (b == '-')
{
printf("The solution to the information given is : %i - %i = %i\n\n", a,c, a - c);
}
elseif (b == '*')
{
printf("The solution to the information given is : %i * %i = %i\n\n", a,c, a * c);
}
elseif (b == '/')
{
printf("The solution to the information given is : %i / %i = %.2f\n\n", a,c, (double)a / c);
}
else
{
printf("The solution to the information given is : %i + %i = %i\n\n", a,c, a + c);
}
getchar();
return 0;
}
well thank you for solving the problem but you did not explain why this is done as i can just type certain things but doesnt mean i will understand why it is done
well thank you for solving the problem but you did not explain why this is done as i can just type certain things but doesnt mean i will understand why it is done
I trust you're capable of doing the work to understand it. It isn't so hard to click on "Reference" in the upper left hand section of this page and find your way to the documentation for scanf.