How to create a faulty calculator in C Programming using If Else?

By | December 4, 2021

Code for faulty calculator whose outcomes will be wrong on these conditions and true results for other calculations using IfElse Statement:

55+6=77

56-4=7

45*3=77 and

56/6=4

```#include<stdio.h>
#include<conio.h>
void main()
{
float a, b, sum, sub, mul, div, inp;
printf("Enter a Operator you want to use: \n 1. Sum\n, 2. Difference \n 3. Multiplication \n 4. Division \n");
scanf("%f");
printf("Enter first number: ");
scanf("%f", a);
printf("Enter Second number: ");
scanf("%f", b);
sum = a + b;
sub = a - b;
mul = a * b;
div = a / b;
if (inp == 1)
{
if (a == 56 & b == 6)
{
printf("Sum is 77");
}
else
{
printf("Sum is %f", sum);
}
if (inp == 2)
{
if (a == 56 & b == 6)
{
printf("Difference is 7");
}
else
{
printf("Difference is %f", sub);
}
}
if (inp == 3)
{
if (a == 45 & b == 3)
{
printf("Product is 77");
}
else
{
printf("Product is %f", mul);
}
}
if (inp == 4)
{
if (a == 56 & b == 6)
{
printf("Division is 4");
}
else
{
printf("Division is %f", div);
}
}
else
{
printf("Enter a valid Operator");
}
}
getch();
}
```