View Full Version : Gratuity Calculator

10-22-2012, 02:58 AM
For my assignment, I have to include input validation if a tax rate that is less than zero is passed to the constructor, with the default rate of .065. It also tells me not to allow the total bill or the tip rate to be less than zero, based on user input. My question is: Isn't the tax rate and tip rate the same? If it isn't, then do I need to set a tax rate to be passed on to the constructor? Where will I set this validation? If it is based on user input doesn't it need to be in main after the user's response? Or, since it is being passed, would I need to include it outside the class with the constructor? Just really confused here, as the directions for the input validation does not make any sense to me.

Here is the input validation question:

Input Validation: If a tax rate of less than 0 is passed to the constructor, use the
default rate of .065. Do not allow the total bill or the tip rate to be less than 0.

And here is my code so far, as I am stuck once I get into main.....

#include <iostream>
#include <iomanip>
using namespace std;

class Tips {

double taxRate;

Tips ();
Tips (double tpFee);
double computeTip(double totalBill, double tipRate);


taxRate = 0.065;

Tips::Tips (double tpFee)
taxRate = tpFee;

double Tips::computeTip(double totalBill, double tipRate)
return (totalBill - (totalBill * taxRate)) * tipRate;

int main()
Tips Tips;
double charge,