i put the numbers into my calculator and i receive a number that is about $1 greater than the actual value. why?
#include<iostream>
#ifndef Tips_H
#define Tips_H
using namespace std;
class Tips
{
private:
long double taxRate,
bill,
gratuity;
public:
Tips()
{
taxRate = 0;
bill = 0;
gratuity = 0;
}
void setTaxRate(double t);
void setBill(double b);
void setGratuity(double g);
void computeTip();
};
#endif
//Tips.cpp
#include<iostream>
#include<iomanip>
#include<cstdlib>
using namespace std;
void Tips::setTaxRate(double t)
{taxRate = t;if(taxRate == 0)taxRate = 0.065;if(taxRate<0){cout << "error! your tax can not be less then zero. pleaase restart program." <<endl;exit(0);}}
void Tips::setBill(double b)
{bill = b;if(bill<=0) {cout<<"Error! Your bill cannont be zero or less. Please re-start this program"<<endl; exit(0);}}
void Tips::setGratuity(double g)
{gratuity = g;if(gratuity<=0) {cout<<"Error! Your gratuity cannont be zero or less. Please re-start this program"<<endl; exit(0);}}
void Tips::computeTip()
{
double output;
output = ((taxRate * bill) + (bill) + (bill * gratuity));
cout << "You've entered: "<<endl;
cout << endl;
cout << fixed << showpoint << setprecision(2) << taxRate << endl;
cout << fixed << showpoint << setprecision(2) << bill << endl;
cout << fixed << showpoint << setprecision(2) << gratuity << endl;
cout << "Your total bill is $ "<< output <<endl;
cout << endl;
}
//main.cpp
#include<iostream>
using namespace std;
int main()
{
long double Tax1,
Bill1,
Grat1;
int choice;
choice = 0;
Tips Ti;
do
{
cout <<"Enter the following to calculate your total bill"<<endl;
cout << endl;
Tax1 = 0.065;
cout << "Tax Rate is "<< Tax1<<endl;
Ti.setTaxRate(Tax1);
cout << endl;
cout << "Enter your bill amount. "<<endl;
cin >> Bill1;
Ti.setBill(Bill1);
cout <<endl;
cout << "Enter the Gratuity Rate You'd like to use (in decimal form)" <<endl;
cin >> Grat1;
cout << endl;
Ti.setGratuity(Grat1);
Ti.computeTip();
cout << "Would you like to calculate again? (Type 1 to repeat or 4 to quit) ";
cin >> choice;
cout << endl;
cout << "-------------------------------------------------------"<<endl;
cout << endl;
}while(choice != 4);
}