forked from AnasImloul/Leetcode-Solutions
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApply Discount Every n Orders.cpp
34 lines (28 loc) · 1.18 KB
/
Apply Discount Every n Orders.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
class Cashier {
public:
int nn = 0;
double dis = 0;
vector<int> pro;
vector<int> pri;
int currCustomer = 0; //Declaring these variables here to use it in other fxns as well
Cashier(int n, int discount, vector<int>& products, vector<int>& prices) {
nn = n;
dis = discount;
pro = products;
pri = prices; //Assigning given values to our created variables
}
double getBill(vector<int> product, vector<int> amount) {
currCustomer++; //Increasing customer count
double bill = 0; //Bill anount set to 0
for(int i = 0; i < product.size(); i++){ //Iterating over every product
int proId = 0;
while(pro[proId] != product[i]) proId++; //Finding product ID index
bill = bill + (amount[i]*pri[proId]); //Adding total amount to bill
}
if(currCustomer == nn){ //Checking if the customer is eligible for discount
bill = bill * (1 - dis/100); //Giving discount
currCustomer = 0; //Setting customer count to 0 so next third person can have discount
}
return bill; //Returning final bill amount
}
};