brain jogged...quick help please
Feb 22, 2016 at 8:46pm UTC
Once the user selects the proper membership, why can't I get the correct rewards (display function) to print??
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;
//function prototypes
void displayStandard(double totalBalance);
void displayPlus(double totalBalance);
void displayPremium(double totalBalance);
int main()
{
char membership = ' ' ;
double balance = 0.0;
double points = 0.0;
cout << "(A) Standard " << endl;
cout << "(B) Plus " << endl;
cout << "(C) Premium " << endl;
cout << "Enter membership type (A, B, C): " ;
cin >> membership;
while (toupper(membership) != 'A' && toupper(membership) != 'B' && toupper(membership) != 'C' )
{
cout << "Please enter A, B, or C: " << endl;
cin >> membership;
}
cout << "Please enter your total monthly purchase: " ;
cin >> balance;
if (membership == 'A' )
displayStandard(points);
else if (membership == 'B' )
displayPlus(points);
else if (membership == 'C' )
displayPremium(points);
system("pause" );
return 0;
}//end of main
//*****function definitions*****
double rewards = 0.0;
void displayStandard(double totalBalance)
{
if (totalBalance < 75)
rewards = .05 * totalBalance;
else if (totalBalance >= 75 && totalBalance <= 149.99)
rewards = .075 * totalBalance;
else (totalBalance >= 150);
rewards = .10 * totalBalance;
cout << fixed << setprecision(0);
cout << "STANDARD " << endl;
cout << "--------" << endl;
cout << "You have earned " <<rewards << " reward points!" << endl << endl;
}//end of standard function
void displayPlus(double totalBalance)
{
if (totalBalance < 150)
rewards = .06 * totalBalance;
else
rewards = .13 * totalBalance;
cout << fixed << setprecision(0);
cout << "PLUS" << endl;
cout << "----" << endl;
cout << "You have earned " <<rewards << " reward points!" << endl << endl;
}//end of plus function
void displayPremium(double totalBalance)
{
if (totalBalance < 200)
rewards = .04 * totalBalance;
else
rewards = .15 * totalBalance;
cout << fixed << setprecision(0);
cout << "PREMIUM" << endl;
cout << "-------" << endl;
cout << "You have earned " << rewards << " reward points!" << endl << endl;
}//end of premium function
Feb 22, 2016 at 8:50pm UTC
Becasue, you save the total monthly purchase in the variable "balance"
1 2
cout << "Please enter your total monthly purchase: " ;
cin >> balance;
Then when you call the function, you hand them the variable "points" -
displayStandard(points);
Which is 0. And anything multiplied with 0 is 0.
I'd also recommend that you create a variable called reward in each function, you don't want global variables like you have right now.
Last edited on Feb 22, 2016 at 8:51pm UTC
Feb 22, 2016 at 9:05pm UTC
I fixed the global reward variable, should i pass the points variable to the functions to get it to work?
Feb 22, 2016 at 9:08pm UTC
fixed the global reward variable, should i pass the points variable to the functions to get it to work?
You are already doing this -
displayPlus(points); // passing points
But if you look at your main. You initialize points -
double points = 0.0;
to 0, then you do nothing with it at all. So then you send it to the function with the value 0, after multiplication get 0.
If "totalBalance" is supposed to represent the value of what the user enters, then you want to pass the balance variable since that is where you store that information
displayPlus(balance);
Last edited on Feb 22, 2016 at 9:15pm UTC
Topic archived. No new replies allowed.