Gratuity Calculator

Hi! I feel this may sound stupid to all of you, but I'm needing some help with some homework.

The assignment is to create a gratuity calculator.

The instructions are as follows:

Design a Tips class that calculates the gratuity on a restaurant meal. Its only class member variable, taxRate, should be set by a one-parameter constructor to whatever rate is passed to it when a Tips object is created. If no argument is passed, a default tax rate of .065 should be used. The class should have just one public function, computeTip. This function needs to accept two arguments, the total bill amount and the tip rate. It should use this information to compute the meal cost before any tax was added. It should then apply the tip rate to just the meal cost portion of the bill to compute and return the tip amount. Demonstrate the class by creating a program that creates a single Tips object, then loops multiple times to allow the program user to retrieve the correct tip among using various bill totals and desired tip rates.
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.


The code I have written is as follows:

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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#include <iostream>
using namespace std;

class Tips{
	public:
		double billTotal;
		double tipRate;
		double mealCost;
		double tipAmount;

	private:
		double taxRate;

	public:
		Tips(double rate){
			if (rate<0)
				taxRate=.065;
			else{
				taxRate=rate;
			}
		}
		
		Tips(){
			taxRate=.065;
		}

		int computeTip(double, double);	
		


};

int Tips::computeTip(double bill, double tip){
			if (bill>0)
				billTotal=bill;
			else{
				cout << "Please enter a value greater than 0 as the bill total:" << endl;
				cin >> bill;
			}
			if (tip>0)
				tipRate=tip;
			else{
				cout << "Please enter a value greater than 0 as the tip rate:" << endl;
				cin >> tip;
			}
			mealCost=billTotal-(billTotal*taxRate);
			tipAmount=tipRate*mealCost;
			cout << "The amount you owe as a tip is $" << tip << endl;


}

int main (){

Tips tip;
tip.computeTip(100, 20);



}



I seem to be having problems with the taxRate? When I run this program, the output is
"The amount you owe as a tip is $20."


Thanks in advance for your help!
Last edited on
The instructions state that the class should have ONE class member called 'taxRate' but in your class you have FIVE member variables. IGF I were you I would sketch out a class on paper using ONLY what has been stipulated.
Topic archived. No new replies allowed.