A local department store wants a program that displays the number of reward poin
ID: 3793708 • Letter: A
Question
A local department store wants a program that displays the number of reward points a customer earns each month. The reward points are based on the customer’s membership type and total monthly purchase amount, as shown in Figure 6-45. If necessary, create a new project named Advanced18 Project, and save it in the Cpp8Chap06 folder. Enter your C++ instructions into a source file named Advanced18.cpp.The program should use a separate function for each membership. Also enter appropriate comments and any additional instructions required by the compiler. Display the reward points in fixed-point notation with no decimal places. Save, run, and test the program. Total monthly Membership type purchase ($) Reward points Standard Less than 75 5% of the total monthly purchase 75–149.99 7.5% of the total monthly purchase 150 and over 10% of the total monthly purchase Plus Less than 150 6% of the total monthly purchase 150 and over 13% of the total monthly purchase Premium Less than 200 4% of the total monthly purchase 200 and over 15% of the total monthly purchase. Here is the my coding
in the out put i dont get the amount of points earned i don't know please help me.
#include <iostream>
#include <iomanip>
using namespace std;
//function prototype
double getRewardsPoints(double purchase, double rate);
int main()
{
//Initialize variables
char type = ' ' ;
double purchase = 0.0;
double points = 0.0;
// Membership types
cout << " Membership type: " << endl;
cout << " Standard = S " << endl;
cout << " Plus = P " << endl;
cout << " Premium = M " << endl;
cout << " Type: ";
cin >> type;
// valid your membership
if (toupper(type) !='S' && toupper(type) !='P' && toupper(type) !='M')
{
//if the membership is not valid show error message and exit the program
cout << " Invalid member type" << endl;
return 0;
}
// Monthly purchase amount
cout <<endl<< "Monthly purchase amount: ";
cin >> purchase;
// checking if purchase is valid
if (purchase < 0 )
{
//if purchase is less than 0 show error message and exit the program
cout << "Error" << endl;
return 0;
}
// Determine amount of points
if (toupper(type)== 'S')
{
//using the getRewardsPoints method get the reward points earned
if (purchase < 75)
points= getRewardsPoints(purchase, 0.05);
else if (purchase >=75 && purchase < 150)
points= getRewardsPoints(purchase, 0.075);
else
points= getRewardsPoints(purchase, 0.1);
}
else if (toupper(type)== 'P')
{
if (purchase < 150)
points=getRewardsPoints(purchase, 0.06);
else
points= getRewardsPoints(purchase, 0.13);
}
else if (toupper(type)== 'M')
{
if (purchase < 200)
points=getRewardsPoints(purchase, 0.04);
else
points= getRewardsPoints(purchase, 0.15);
}
// Display the amount of points
cout << fixed << setprecision (0);
cout <<endl<<"Amount of points earned:" << points << endl<<endl;
system("pause");
return 0;
}
//function definitions
double getRewardsPoints(double purchase, double rate )
{
double rewardsPoints = 0.0;
//calculate and return the reward points
rewardsPoints= purchase * rate;
return rewardsPoints;
// end of getRewardsPoints
}
Explanation / Answer
#include <iostream>
#include <iomanip>
using namespace std;
//function prototype
double getRewardsPoints(double purchase, double rate);
int main()
{
//Initialize variables
char type = ' ' ;
double purchase = 0.0;
double points = 0.0;
// Membership types
cout << " Membership type: " << endl;
cout << " Standard = S " << endl;
cout << " Plus = P " << endl;
cout << " Premium = M " << endl;
cout << " Type: ";
cin >> type;
// valid your membership
if (toupper(type) !='S' && toupper(type) !='P' && toupper(type) !='M')
{
//if the membership is not valid show error message and exit the program
cout << " Invalid member type" << endl;
return 0;
}
// Monthly purchase amount
cout <<endl<< "Monthly purchase amount: ";
cin >> purchase;
// checking if purchase is valid
if (purchase < 0 )
{
//if purchase is less than 0 show error message and exit the program
cout << "Error" << endl;
return 0;
}
// Determine amount of points
if (toupper(type)== 'S')
{
//using the getRewardsPoints method get the reward points earned
if (purchase < 75)
points= getRewardsPoints(purchase, 0.05);
else if (purchase >=75 && purchase < 150)
points= getRewardsPoints(purchase, 0.075);
else
points= getRewardsPoints(purchase, 0.1);
}
else if (toupper(type)== 'P')
{
if (purchase < 150)
points=getRewardsPoints(purchase, 0.06);
else
points= getRewardsPoints(purchase, 0.13);
}
else if (toupper(type)== 'M')
{
if (purchase < 200)
points=getRewardsPoints(purchase, 0.04);
else
points= getRewardsPoints(purchase, 0.15);
}
// Display the amount of points
cout << fixed << setprecision (0);
cout <<endl<<"Amount of points earned:" << points << endl<<endl;
system("pause");
return 0;
}
//function definitions
double getRewardsPoints(double purchase, double rate )
{
double rewardsPoints = 0.0;
//calculate and return the reward points
rewardsPoints= purchase * rate;
cout<<"rate"<<rate<<endl;
double amountearned=(purchase/100)*rewardsPoints;
cout<<"amount you earned "<<amountearned<<endl;
return rewardsPoints;
// end of getRewardsPoints
}
output
Membership type:
Standard = S
Plus = P
Premium = M
Type: S
Monthly purchase amount: 98
rate0.075
amount you earned 7.203
Amount of points earned:7
Press any key to continue . . .
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.