-
Notifications
You must be signed in to change notification settings - Fork 23
/
12.cpp
58 lines (51 loc) · 1.29 KB
/
12.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/*
Create a four-function calculator for fractions. (See Exercise 9 in Chapter 2, and
Exercise 4 in this chapter.) Here are the formulas for the four arithmetic operations
applied to fractions:
The user should type the first fraction, an operator, and a second fraction. The program
should then display the result and ask whether the user wants to continue.
*/
//author @Nishant
#include<iostream>
using namespace std;
int main(){
char ch;
do{
int a, b, c, d, num, den;
char temp, option;
cout << "Enter first fraction: ";
cin >> a >> temp >> b;
cout << "Operator: ";
cin >> option;
cout << "Enter second fraction: ";
cin >> c >> temp >> d;
switch(option){
case '+':
num = a * d + b * c;
den = b * d;
cout << "Sum is: " << num << "/" << den << endl;
break;
case '-':
num = a * d - b * c;
den = b * d;
cout << "Subtraction is: " << num << "/" << den << endl;
break;
case '*':
num = a * c;
den = b * d;
cout << "Multiplication is: " << num << "/" << den << endl;
break;
case '/':
num = a * d;
den = b * c;
cout << "Division is: " << num << "/" << den << endl;
break;
default:
cout << "Invalid option";
break;
}
cout << "Do you want to continue (y/n): ";
cin >> ch;
}while(ch == 'y');
return 0;
}