Answer:
How to calculate the total cost of the meal
For bill inclusive of tax, cost1=cost*(1+tax percentage)
For bill inclusive of tax and tip, cost2=cost1*(1+tip percentage)
Meal cost =(pizza cost*(1+tax percentage))*(1+tip percentage)
Now how to calculate the cost per person
cost per person=meal cost/ number of people.
C language code to solve the above problem is given below with appropriate comments for explanation
Explanation:
#include<stdio.h>
float split_bill(int cost,float tax)
{
//Declaring number of people as int
int number;
//Prompting for number of people
printf("Enter number of people ");
scanf("%d",&number);
//Declaring tip percentage as float
float tip_percent;
//Prompting for tip percentage
printf("Enter tip percentage between 0 and 1 ");
scanf("%f",&tip_percent);
//Calculating total meal cost
float meal=(((float)cost)*(1+tax))*(1+tip_percent);
//Printing total cost of meal
printf("Total cost of meal: %0.2f ",meal);
//Calculating cost per person
float cost_per_person=meal/number;
//Returning cost per person to main function
return cost_per_person;
}
int main()
{
//Declaring pizza cost as int and tax percentage as float
int pizza_cost;
float tax_percent;
//Prompting user for pizza cost
printf("Enter billing amount of pizza ");
scanf("%d",&pizza_cost);
//Prompting user for tax percentage
printf("Enter tax percentage between 0 and 1 ");
scanf("%f",&tax_percent);
//Printing the cost per person by calling the function split_bill
printf("Total cost per person is: %0.2f ",split_bill(pizza_cost,tax_percent));
return 0;
}