-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy path11.cpp
62 lines (55 loc) · 1.47 KB
/
11.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
59
60
61
62
/*
Create a three-function calculator for old-style English currency, where money amounts
are specified in pounds, shillings, and pence. (See Exercises 10 and 12 in Chapter 2.)
The calculator should allow the user to add or subtract two money amounts, or to multi-
ply a money amount by a floating-point number.
*/
// author @Nishant
#include<iostream>
using namespace std;
int main(){
char ch;
do{
char temp;
char option;
int pounds1, shillings1, pence1, pounds2, shillings2, pence2;
cout << "Enter first amount: £";
cin >> pounds1 >> temp >> shillings1 >> temp >> pence1;
cout << "Enter second amount: £";
cin >> pounds2 >> temp >> shillings2 >> temp >> pence2;
cout << "Operation +, -, *: ";
cin >> option;
switch(option){
case '+':
pounds1 += pounds2;
shillings1 += shillings2;
pence1 += pence2;
break;
case '-':
pounds1 -= pounds2;
shillings1 -= shillings2;
pence1 -= pence2;
break;
case '*':
pounds1 *= pounds2;
shillings1 *= shillings2;
pence1 *= pence2;
break;
default:
cout << "Invalid option" << endl;
break;
}
if(pence1 > 11){
shillings1 += (pence1/12);
pence1 = pence1%12;
}
if(shillings1 > 19){
pounds1 += (shillings1/20);
shillings1 = shillings1%20;
}
cout << "Amount after performing " << option << " is £" << pounds1 << "." << shillings1 << "." << pence1 << endl;
cout << "Do you want to continue (y/n): ";
cin >> ch;
}while(ch == 'y');
return 0;
}