1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Dahasolnce [82]
3 years ago
14

You and a few friends are having a meal at a pizza restaurant, and the server has just given you the bill. Write a function that

asks the user how many people there are total and what percent they'd like to tip the server. Then, given the cost of the pizza and the tax rate as a percentage, calculate the total cost of the meal and return how much each person must pay rounded to 2 decimal places. Note that the tax should be calculated and added to the total, and the tip amount should be determined based on the total including tax. Additionally, you may assume that the parameters will always follow the types listed above. The user will always pass in an integer for the number of people, but the tip could be either an int or a float. The percentages given for tax and tip will always be between 0 and 1 inclusive. There will always be at least one person.
Function name : split_bill()
Parameters : pizza_cost (int), tax_percent (float)
Returns: total_cost (float)
Computers and Technology
1 answer:
cestrela7 [59]3 years ago
8 0

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;

}

You might be interested in
Write a program that simulates rolling one die using the following steps: 1. Prompt the user for the number of sides on the die.
Mashcka [7]

Answer:

The program to the given question can be given as:

Program:

//import package.

import java.util.*;                    

//define class.

public class Main                    

{

 public static void main(String ar[])  //define main method.  

 {

Scanner  ob = new Scanner(System.in);     //creating scanner class object.

   Random ran = new Random();                 //creating random class object.

   int roll1,roll2,roll3,number,total=0;          //define variable.

   float avg=0;

   System.out.print("Enter the sides= ");           //print message.

   number = scanner.nextInt();                 //input number by user.

   roll1 = ran.nextInt(number++);         //using random function.

   roll2 = ran.nextInt(number++);

   roll3 = ran.nextInt(number++);

   System.out.print("First roll= ");           //print message

   System.out.println(roll1);               //print value.

   System.out.print("Second roll= ");

   System.out.println(roll2);

   System.out.print("Third roll= ");

   System.out.println(roll3);

   System.out.print("total roll= ");

   total=roll1+roll2+roll3;                            //add all number.

   System.out.println(total);

   System.out.print("Average roll= ");                      

   avg=total/3;                                 //Average of the number.

   System.out.println(avg);

 }

}

Output:

Enter the sides= 4

First roll= 2

Second roll= 3

Third roll= 5

total roll= 10

Average roll= 3.0

Explanation:

In the above program first, we import the package form the user input and random number. In java, there are many packages but we use only the util package because in that package both the class like scanner class and random class are inbuilt. Then we declare the class that name is Main in that class we define the main function. In the main function, we create both class object (scanner class and random class). Then we take input a number from the user and pass into the random function. The random function is used to give a unique number and we pass the number into the random function that is increasing by post-increment operator i.e (X++). Then we print all the rolls and total by add all the roll and at the last, we print an average of it.

7 0
3 years ago
What is achieved through xylography
ryzh [129]
As a relief method, it is only necessary to ink the block and bring it into firm and even contact with the paper or cloth to achieve an acceptable print.
4 0
3 years ago
Read 2 more answers
Write a computer program that computes the duration of a projectile’s flight and its height above the ground when it reaches the
Citrus2011 [14]

Answer:

#include <stdio.h> #define Gray 32.17 /* gravitational constant */ #include <math.h> /*cos definition*/ #define PI 3.14159265

int main(void) double Theta; /*input-angle(radians)of elevation*/ double Distance; /*input-distance (ft) to target */ double Velocity; /*input-projectile velocity (ft/sec)*/ double Time; /* output-time(sec) of flight*/ double Height; /*output-height at impact*/

printf("Enter Distance> "); scanf("%f", &Distance);

printf("Enter Radians> "); scanf("%f", &Theta);

printf("Enter Velocity> "); scanf("%f", &Velocity

Time = Distance / (Velocity * cos(Theta*PI/180.0) ) ;

Height = (Velocity *sin(Theta*PI/180.0)*Time) - Grav*(Time* Time) );

printf("The time of flight is %.3f seconds.\n", Time); printf("The height at impact is %.3f feets.\n", Height);

system("pause");

return (0);

7 0
3 years ago
If you are viewing a webpage with customized or regenerated content, such as updated stock quotes, what type of webpage are you
horsena [70]

Answer:

Dynamic

Explanation:

A dynamic web page is a type of web page that shows different and diverse content each time it's viewed. For instance, the webpage may adjust with every passing time of day, it might also change according to the different preference of each user that accesses the webpage, or the kind of user interaction.

5 0
4 years ago
Drag the tiles to the correct boxes to compete the pairs.
levacccp [35]

Provides the fescription of a grammar error = Explain

Changes all occurrences of the misspelled words = Change all

Change the behavior of the grammar checker = Options

Enables you to add or remove misspelled words = Replace


3 0
3 years ago
Read 2 more answers
Other questions:
  • To move down one paragraph, press the ____ key(s).
    15·1 answer
  • What does an executable file contain? Program instructions written in source code. Program instructions that have been compiled
    15·1 answer
  • Which of the following is not a protocal? <br><br>A) HTTP<br>B) FTP<br>C) WWW<br>D) HTTPS​
    15·2 answers
  • _______ memory allows data to be both read from and written to easily and rapidly.
    7·1 answer
  • Software people commonly use in the workplace to make their life easier is called?
    11·2 answers
  • The following are types of numbers except one. Select the one which is not an integer.
    11·1 answer
  • Dictionaries You are given a dictionary consisting of word pairs. Every word is a synonym the other word in its pair. all the wo
    9·1 answer
  • In the Business world people are often measured by their???
    14·1 answer
  • Write the steps involving coping and pasting a file in a folder​
    5·1 answer
  • The different languages that follow specific RULES. These languages use commands
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!