Expand|Select|Wrap|Line Numbers
- #include <iostream>
- #include <iomanip>
- #include <cmath>
- using namespace std;
- class Tips {
- private:
- double taxRate;
- public:
- Tips();
- Tips(double tRate);
- double computeTip(double totalBill, double tipRate);
- };
- Tips::Tips()
- {
- taxRate = 0.065;
- }
- Tips::Tips(double tRate)
- {
- taxRate = tRate;
- }
- double Tips::computeTip(double totalBill, double tipRate)
- {
- return (totalBill + (totalBill * taxRate));
- }
- int main()
- {
- int choice;
- double charge,
- bonus,
- saleTx;
- bool running = true;
- while (running)
- {
- cout << "Please enter the amount before tax.";
- cin >> charge;
- if (charge < 0)
- { cout << "Invalid entry. Negative numbers are not accepted.";
- cout << "Please enter only positive values";
- cin >> charge;
- }
- cout << "Please enter the sales tax charged to the bill";
- cin >> saleTx;
- Tips tips(saleTx);
- cout << "Please enter the tip rate given";
- cin >> bonus;
- if (bonus < 0)
- { cout << "Invalid entry. Negative numbers are not accepted.";
- cout << "Please enter only postive values";
- cin >> bonus;
- }
- cout << "Your tip is: " << tips.computeTip(charge, bonus) << endl;
- return 0;
- }
- }