-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExtractingDecimals.cpp
More file actions
44 lines (30 loc) · 938 Bytes
/
ExtractingDecimals.cpp
File metadata and controls
44 lines (30 loc) · 938 Bytes
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
#include <bits/stdc++.h>
using namespace std;
int totalCost;
void solve (double meal_cost, int tip_percent, int tax_percent) {
double tip;
double taxes;
double tempCost, numAfterDecimal;
tip = (((double)tip_percent*1/100)*meal_cost);
taxes (((double)tax_percent*1/100)*meal_cost);
tempCost = meal_cost+tip+taxes;
numAfterDecimal = fmod(tempCost,1);
if (numAfterDecimal > .5) {
totalCost = (int)tempCost + 1;
} else {
totalCost = (int)tempCost;
}
int main () {
double meal_cost;
cin >> meal_cost;
cin.ignore(numeric_limits<streamsize>::max(), '\n');
int tip_percent;
cin >> tip_percent;
cin.ignore(numeric_limits<streamsize>::max(), '\n');
int tax_percent;
cin >> tax_percent;
cin.ignore(numeric_limits<streamsize>::max(), '\n');
solve(meal_cost, tip_percent, tax_percent);
cout << totalCost << endl;
return 0;
}