-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathc.c
47 lines (45 loc) · 1.62 KB
/
c.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#include <stdio.h>
#include <conio.h>
double calculate(double a,double b,int c)
{
if(c==1)return a+b;
if(c==2)return a-b;
if(c==3)return a*b;
if(c==4)return a/b;
}
int main()
{
double operand1,operand2,answer;
int operation,choice;
while(true)
{
printf("Enter First Operand: ");
scanf("%lf",&operand1);
printf("Enter Second Operand: ");
scanf("%lf",&operand2);
printf("\nChoose operation! (Please enter only integral values)");
printf("\n1 For Addition");
printf("\n2 For Subtraction");
printf("\n3 For Multiplication");
printf("\n4 For Division\n");
scanf("%d", &operation);
if(operation<1 || operation > 4) {
printf("Wrong Input, Try Again !!\n");
printf("-------------------------\n");
continue;
}
if(operation==4 && operand2==0) printf("\nError - Division by zero !!\n");
else {
answer = calculate(operand1,operand2,operation);
if(operation==1) printf("\n %lf + %lf = %lf\n",operand1,operand2,answer);
if(operation==2) printf("\n %lf - %lf = %lf\n",operand1,operand2,answer);
if(operation==3) printf("\n %lf * %lf = %lf\n",operand1,operand2,answer);
if(operation==4) printf("\n %lf / %lf = %lf\n",operand1,operand2,answer);
}
printf("Enter 0 to exit the calculator or 1 to continue.\n");
scanf("%d",&choice);
if(choice==0)break;
else {printf("-------------------------\n");continue;}
}
return 0;
}