Hello and thanks in advance for your help. My program calculates the gratuity of various bills and gives the user how much to leave for a tip. If the user enters a negative amount for the tax, the default constructor is supposed to use 6.5%. My program compiles, but instead of subtracting the tax, it adds to it (when using a negative). What am I doing wrong?
Here is my code:
#include <iostream>
#include <iomanip>
using namespace std;
//Create the class
class Tips
{
public:
double tar;
Tips()
{if (tar < 0)
tar = 6.5;
}
double computeTip(double, double, double);
};
double Tips::computeTip(double t, double tir, double tar)
{
double total = t;
double tipRate = tir;
double taxRate = tar;
double meal;
double tip;
while (t != 999)
{
cout << "Enter the total cost of the meal: ";
cin >> t;
if (t < 0)
{cout << "Invalid entry. Please enter a number greater than 0: ";
cin >> t;
}
cout << "Enter the amount of tax: ";
cin >> tar;
Tips::Tips();
meal = (t / (tar + 100)) * 100;
cout << "The total amount of the meal before tax is: ";
cout << setprecision(4) << meal;
cout << endl;
cout << "Enter the tip percentage you would like to leave: ";
cin >> tir;
if (tir < 0)
{cout << "Invalid entry. Please enter a number greater than 0: ";
cin >> tir;
}
tip = meal * (tir / 100);
cout << "The tip rate you would like to leave is: " << tir / 100 << endl;
cout << "The amount of the tip you should leave is: " << setprecision(3) << tip << endl;
cout << endl;
}
return tip;
}
int main()
{
Tips bill;
double billRate, billMeal, billTir, billTip;
cout << "This program computes the gratuity at a restaurant. Enter 999 to quit.";
cout << endl;
cout << endl;
bill.computeTip(billTir, billTip, billRate);
system("pause");
return 0;
}