In: Computer Science
This assignment is For a C++ class , I am having difficulty with getting the boolean statements the most; getting them set up properly inside the int main() area.
You have been asked to define a tip-calculating function named calcTip that could be integrated into a larger piece of software designed to improve guest service at a restaurant. As a result, you must conform to the function specification used throughout the rest of the project's code:
double calcTip(double checkAmount, bool postTax, bool round);
This function, when called, calculates and returns a tip amount
in U.S. dollars determined by the values of its two boolean
parameters. Any extra comments with guidance will be very
apprectiated, thank you so much!
----
tipCalc's parameters:
checkAmount:
The amount of a check in U.S. dollars with tax included.
Ex. a value of 15.00 represents $15.00 USD.
postTax:
The value of the postTax parameter determines whether the function calculates a tip before or after the tax has been added to a check amount.
A value of true means that the calculated tip will be based off the entire check amount.
A value of false indicates that tax must be removed from the check amount before a tip is calculated.
round:
The value of the round parameter determines whether or not the tip amount is rounded up before being returned. A value of true indicates that the value will be rounded up.
----
Assume that the tax rate for meals is a fixed
7.8% regardless of the geographical region in
which
this software may be used. Also, in the interest of elevating the
standard of what constitutes a
good tip, the tip rate is a fixed
20%.
As examples, a tip calculated for an entire $20.00 check (which includes tax) without rounding would be $4.00. A tip calculated for only the pre-tax amount of a $20.00 check without rounding would be $3.69.
Implementation
You must not make any changes to the calcTip's
return type or parameters.
----
In main, you must prompt for and accept user input that will be
used as arguments for a calcTip function call.
You have the freedom to structure main as you see fit, provided that I can execute your program and specify the following before a call to calcTip is made:
1.) the amount of the check after tax has been
applied (e.g. I can enter $20.00 or similar)
2.) whether or not I want my tip to be calculated off the full
check (i.e. including tax)
3.) whether or not I want to round up my tip to the nearest U.S.
dollar
You must not prompt for this input inside calcTip().
----
Once this is done, a function call to calcTip must be made inside
main; its return value
will be output.
Results
Output the following text in main after making the call to calcTip:
Your tip amount is $[TIP AMOUNT]
In order to verify program correctness, you should run the program four times under the following conditions:
1.) The user wants a 20% tip on a $15 check
before tax with no rounding.
2.) The user wants a 20% tip on a $15 check after
tax with no rounding.
3.) The user wants a 20% tip on a $15 check before
tax with rounding.
4.) The user wants a 20% tip on a $15 check after
tax with rounding.
Thanks for the question.
Here is the completed code for this problem.
Comments are included, go through it, learn how things work and let me know if you have any doubts or if you need anything to change. If you are satisfied with the solution,
please rate the answer. Thanks
===========================================================================
#include<iostream>
#include<cmath>
#include<iomanip>
using namespace std;
double calcTip(double checkAmount, bool postTax, bool round);
double calcTip(double checkAmount, bool postTax, bool
round){
const double TAX_RATE = 0.078; // constant rates
const double TIP_RATE = 0.2; // constant rates
double tipAmount;
// postTax is true then we first need to calculate the
total amount
// and then apply the tip rate on that total
amount
if(postTax){
tipAmount =
TIP_RATE*(checkAmount/(1+TAX_RATE));
}else{
// if post tax is false, then we
apply the tip rate on the check amount
tipAmount =
TIP_RATE*checkAmount;
}
// if the round is true we use the next largest
integer
if(round)return ceil(tipAmount);
// else we simply return the calculated tip amount
withoout rounding off
else return tipAmount;
}
int main() {
double checkAmount;
cout<<"Enter check amount: ";
cin>>checkAmount;
int choice;
cout<<"Type 1-Post Tax, Type 2-Pre Tax: ";
cin>>choice;
bool postTax = choice==1;
cout<<"Type 1-Round, Type 2-Do not Round: ";
cin>>choice;
bool round = choice==1;
double tip = calcTip(checkAmount,postTax,round);
cout<<fixed<<showpoint<<setprecision(2);
cout<<"\nTip Amount:
$"<<tip<<endl;
}
===============================================================
Let me know in case you have any questions. or need any help;