Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CPP

c++ calculator

1 #include<stdio.h>
 2 
 3 int main(){
 4 
 5     char operator;
 6     double first, second;
 7 
 8     printf("Enter the Operator ( +, -, *, / ) : ");
 9     scanf("%c",&operator);
10 
11     printf("Enter the two Numbers one by one : ");
12     scanf("%lf %lf",&first,&second);
13 
14     switch (operator)
15     {
16 
17     case '+':
18         printf("%.2lf + %.2lf = %.2lf",first,second,(first+second));
19         break;
20         
21     case '-':
22         printf("%.2lf - %.2lf = %.2lf",first,second,(first-second));
23         break;
24 
25     case '*':
26         printf("%.2lf * %.2lf = %.2lf",first,second,(first*second));
27         break;
28 
29     case '/':
30         if( second != 0.0 )
31             printf("%.2lf / %.2lf = %.2lf",first,second,(first/second));
32         else 
33             printf("Divide by Zero situation");
34         break;
35     
36     default:
37         printf("%c is an invalid Operator",operator);
38         
39     }
40 
41     return 0;
42 }
Source by www.learninglad.com #
 
PREVIOUS NEXT
Tagged: #calculator
ADD COMMENT
Topic
Name
5+8 =