# In a pseudocode program,,,write a program that computes and displays a 15b percent tip when the price of a meal input by the user.(Hint: the tip is computed by multiplying the price of the meal by 0.15 ) You will need the following Variables: MealPrice (a Float) Tip (a Float)

To accomplish the completion of this program, you would only need a single function to determine the tip total. The function would look something like this:

public float getTip(float mealPrice) {

return mealPrice * 0.15;

}

Just as a reminder, since we have a constant (0.15), it is good coding practice to have a final variable at the top (above your main function) that can be in place instead of a hard coded value. A final variable at the top makes the code look much more readable. The variable can be at the top, like so:

private static final float TIP_PERCENTAGE = 0.15f;

Then the function would look like this:

public float getTip(float mealPrice) {

return mealPrice * TIP_PERCENTAGE;

}

Finally, this is how you would call the function and display the calculation:

public static void main(String[] args) {

float mealPrice = 5.00f;

float calculation = getTip(mealPrice);

System.out.println("Price: " + calculation);

}

check Approved by eNotes Editorial

mike0robertson | Student

I have prepared a very simple solution to your problem written in Python:

def tip_calc(MealPrice):

tip = MealPrice * 0.15

return tip

The same algorithm in c:

float tip_calc(float MealPrice){

float tip = MealPrice * 0.15;

return tip;

}

In plain english(pseudocode) I will explain the algorithm step by step.

We have a function named 'tip_calc' and we pass the variable 'MealPrice' to it.

In the body of the function, the 'MealPrice' is multiplied by 0.15 and stored in the variable named 'tip'.

Finally, 'tip' is returned to the calling function

In some languages, like C++ and Java you have to declare your variables type. In this case, the type is float. This just gets the computer ready to accept floating point variables.

A floating point variable is what most people would call a decimal. For example, 1.77 or .0111 are both floating point numbers.