Please help fix

I'm working on a program that is suppose to display the amount of reward points a customer has accumulated based on their membership type and amount of monthly purchases. There are three membership types: Standard, Plus, and Premium. The rewards accumulated are based on how much the member has spent.
Example:
-Standard members receive rewards equaling 5% of monthly purchases if they've spent less than $75, 7.5% if they've spend more than $75, but less than $149.99, and 10% for any amount above $149.99
-Plus members receive 6% of monthly purchases if they've spent less than $150, and 13% for any amount above $149.99
-Premium members receive 4% of monthly purchases if they've spent less than $200 and 15% for any amount above $199.99
My program will only display 0 as points accumulated. I have to use voids. Please Help.
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#include <iostream>
#include <iomanip>
using namespace std;


void rewardPointsST(double &total);
void rewardPointsPL(double &total);
void rewardPointsPM(double &total);
int main()
{
   // Declare variables
   char memberType = ' ';
   double monthlyPurchase = 0.0;
   double rewardPoints = 0.0;
   cout << "Standard = 'S'" << endl << "Plus= 'P'" << endl << "Premium= 'M'" << endl << "Enter Member Type: " << endl;
   cin >> memberType;
   while (toupper(memberType) != 'S' && toupper(memberType) != 'P' && toupper(memberType) != 'M')
   {
       cout << " Invalid member type! Guess again:" << endl;
       cin >> memberType;
   }
   cout << "Please enter your monthly purchase: " << endl;
   cin >> monthlyPurchase;
   cout << fixed << setprecision(0);
  
   if (toupper(memberType) == 'S')
   {
        rewardPointsST(monthlyPurchase);
       cout << " Monthly purchase $ " << monthlyPurchase << " accumalated " << rewardPoints << " points" << endl;
   }
   if (toupper(memberType) == 'P')
   {
       rewardPointsPL(monthlyPurchase);
       cout << " Monthly purchase $ " << monthlyPurchase << " accumalated " << rewardPoints << " points" << endl;
   }
   if (toupper(memberType) == 'M')
   {
       rewardPointsPM(monthlyPurchase);
       cout << " Monthly purchase $ " << monthlyPurchase << " accumalated " << rewardPoints << " points" << endl;
   }
   system("Pause");
   return 0;
   }
//end main function

//*****Function Definitions*****
void rewardPointsST(double &total)
{
   double rewardPoints = 0.0;
  
   if (total < 75 && total >= 0)
   {
       rewardPoints = total * .05;
   }
   else if (total >= 75 && total <= 149.99)
   {
       rewardPoints = total * .075;
   }
   else if (total >= 150)
   {
       rewardPoints = total * .1;
   }
   else
       cout << "Wrong entry please put valid input";
}
//end Standard type function
void rewardPointsPL(double &total)
{
   double rewardPoints = 0.0;
   if (total < 150 && total >= 0)
   {
       rewardPoints = total * .06;
   }
   else if (total >= 150)
   {
       rewardPoints = total * .13;
   }
   else
       cout << "Wrong entry please put valid input";
}
//end Plus type function
void rewardPointsPM(double &total)
{
   double rewardPoints = 0.0;
  
   if (total < 200 && total >= 0)
   {
       rewardPoints = total * .04;
   }
   else if (total >= 200)
   {
       rewardPoints = total * .15;
   }
   else
       cout << " Wrong entry please put valid input";
}
//end. 
remember to also pass your rewardPoints variable into your functions.

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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#include <iostream>
#include <iomanip>
using namespace std;


void rewardPointsST(double &total, double &);
void rewardPointsPL(double &total, double &);
void rewardPointsPM(double &total, double &);

int main()
{
	// Declare variables
	char memberType = ' ';
	double monthlyPurchase = 0.0;
	double rewardPoints = 0.0;
	cout << "Standard = 'S'" << endl << "Plus= 'P'" << endl << "Premium= 'M'" << endl << "Enter Member Type: " << endl;
	cin >> memberType;
	while (toupper(memberType) != 'S' && toupper(memberType) != 'P' && toupper(memberType) != 'M')
	{
		cout << " Invalid member type! Guess again:" << endl;
		cin >> memberType;
	}
	cout << "Please enter your monthly purchase: " << endl;
	cin >> monthlyPurchase;
	cout << fixed << setprecision(0);

	if (toupper(memberType) == 'S')
	{
		rewardPointsST(monthlyPurchase, rewardPoints);
		cout << " Monthly purchase $ " << monthlyPurchase << " accumalated " << rewardPoints << " points" << endl;
	}
	if (toupper(memberType) == 'P')
	{
		rewardPointsPL(monthlyPurchase, rewardPoints);
		cout << " Monthly purchase $ " << monthlyPurchase << " accumalated " << rewardPoints << " points" << endl;
	}
	if (toupper(memberType) == 'M')
	{
		rewardPointsPM(monthlyPurchase, rewardPoints);
		cout << " Monthly purchase $ " << monthlyPurchase << " accumalated " << rewardPoints << " points" << endl;
	}
	system("Pause");
	return 0;
}
//end main function

//*****Function Definitions*****
void rewardPointsST(double &total, double &rewardPoints)
{
	rewardPoints = 0.0;

	if (total < 75 && total >= 0)
	{
		rewardPoints = total * .05;
	}
	else if (total >= 75 && total <= 149.99)
	{
		rewardPoints = total * .075;
	}
	else if (total >= 150)
	{
		rewardPoints = total * .1;
	}
	else
		cout << "Wrong entry please put valid input";
}
//end Standard type function
void rewardPointsPL(double &total, double &rewardPoints)
{
	rewardPoints = 0.0;
	if (total < 150 && total >= 0)
	{
		rewardPoints = total * .06;
	}
	else if (total >= 150)
	{
		rewardPoints = total * .13;
	}
	else
		cout << "Wrong entry please put valid input";
}
//end Plus type function
void rewardPointsPM(double &total, double &rewardPoints)
{
	rewardPoints = 0.0;

	if (total < 200 && total >= 0)
	{
		rewardPoints = total * .04;
	}
	else if (total >= 200)
	{
		rewardPoints = total * .15;
	}
	else
		cout << " Wrong entry please put valid input";
}
//end.  
Last edited on
Hello Russderp,

Another option that would combine all three function into one.

As Global variables:

1
2
3
4
5
constexpr double STRATE1{ 0.05 };
constexpr double STRATE2{ 0.075 };
constexpr double STRATE3{ 0.1 };

// Same concept for the other two levels. 

This way should any of these rates need to be changed you will only have one place to change them.

Then your function call would be:
rewardPoints = RewardPoints(monthlyPurchase, STRATE1, STRATE2, STRATE3);

i would do the function definition as:
double RewardPointsPM(const double &total, double rate1, double rate2, double rate 3)

Keep in mind I have not tested this yet, but the concept is good.

Hope that helps,

Andy
Hello Russderp,

Yesterday when I wrote the last message I was interrupted and lost my thought. That is why I ended up thinking that all three functions could be done in one. When I started working on the program I realized different.

The function call only needs to be: rewardPoints = RewardPointsPM(monthlyPurchase); and in the function definition all you need is: double RewardPointsST(const double total). "total" does not need to be passed by reference because you should not be changing this variable in this function. And the type of variable is not a porblem to pass by value.

Variables like "STRATE1" do not need passed to the functions because they are global variables and any code in the file has access to them.

Inside the three "rewardPoints" functions since all the if/else if statements are one line statements the {}s are not needed. As an example you could write the if/else if statements as return rewardPoints = total * STRATE1;. It works the same with or without the return. The single else statement should not be here. By the time you get to these functions the variable being passed should be verified and correct to start with.

If I missed anything or you do not understand let me know.

Hope that helps,

Andy
Topic archived. No new replies allowed.