#include <iostream> //class for stream input/output
using namespace std; //use the standard namespace
/************************************************************
** This function will determine the **
** the number of people at the table. **
*************************************************************/
int numPeopleVal = 0;
void numPeople ()
{
cout << "Please enter the number of people at the table. (1, 3, 4): " <<endl;
cin >> numPeopleVal;
}
/************************************************************
** This function will determine the tip percentage based **
** on the number of people at the table. **
*************************************************************/
float tipPercent ()
{
if (numPeopleVal < 5)
{
return 0.15;
}
else
{
return 0.18;
}
}
/************************************************************
** This function will determine the cost of the orders **
** and loop it until it takes as many orders as people **
** at the table. **
*************************************************************/
float costOfOrders ()
{
numPeople ();
int np = numPeopleVal;
float costOrders = 0;
float costOrdersSum = 0;
while (np > 0)
{
cout << "\nPlease enter the cost of order " << np << "(20.34, 14.20):";
np--;
cin >> costOrders;
costOrdersSum += costOrders;
}
return costOrdersSum;
}
int main () //start of main function
{
//costOfOrders();
//numPeople();
//tipPercent();
const float SALESTAX = 0.06; // Constant for Sales Tax, 6 percent.
float costOfOrdersF = costOfOrders ();
float tipPercentF = tipPercent ();
//cout << "Please enter the cost of order " << numPeople() << "(20.34, 14.20):" <<endl;
//These are the computations used to fint the total tax, tip, and subtotal of the bill.
float totalTax = SALESTAX * costOfOrdersF;
float totalTip = tipPercentF * costOfOrdersF;
float subTotal = totalTax + totalTip + costOfOrdersF;
// Here the functions are called and results are displayed.
cout << "totalTax: " << totalTax << "\n" << "totalTip: " << totalTip <<"\n" << "subTotal: " << subTotal << "\n";
return 0;
}