-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCalcualator.cpp
41 lines (41 loc) · 853 Bytes
/
Calcualator.cpp
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
#include<stdio.h>
// Calculator making Using switch case
int main(){
char op;
double num1, num2;
printf("Welcome to Standard Calculator\n");
printf("\n");
printf("Enter what operator you want to use: \n");
scanf("%c",&op);
printf("Enter First input number:\n");
scanf("%lf",&num1);
printf("Enter Second input number:\n");
scanf("%lf",&num2);
double ans;
switch(op){
case '+':
ans = num1 + num2;
printf("Your answer is %.4lf",ans);
break;
case '-':
ans = num1 - num2;
printf("Your answer is %.4lf",ans);
break;
case '*' :
ans = num1 * num2;
printf("Your answer is %.4lf",ans);
break;
case '/' :
if(num2==0){
printf("Your second number input is wrong");
}
else{
ans = num1 / num2;
printf("Your answer is %.4lf",ans);
}
break;
default:
printf("Your input operator is wrong\n");
}
return 0;
}