{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

ps6solnsF06

# ps6solnsF06 - %Engineering 6 Fall 2006 Problem 6.1(function...

This preview shows pages 1–2. Sign up to view the full content.

%Engineering 6, Fall 2006, Problem 6.1 (function file) %(Meal cost calculator) function [tip15, cost15, tip20, cost20] = mealcost(price) %MEALCOST calculates the tip and total cost for a meal %Calculate 15 percent tip and total cost of meal tip15 = 0.15*price; cost15 = price + tip15; %Calculate 20 percent tip and total cost of meal tip20 = 0.2*price; cost20 = price + tip20; %Engineering 6, Fall 2006, Problem 6.2 Solution %(Meal tip and cost calculator using user-defined function) %Suppress extra lines in output and set fixed short display format compact ; format short ; clc; %Clear command window clear; %Clear variables %Get meal cost from user disp( 'Meal Tip and Cost Calculator' ); cost = input( 'Enter the cost of the meal in dollars and cents (e.g., 19.65): ' ); %Call meal tip and cost calculation function (returns amounts for %15 percent tip and total cost and for 20 percent tip and total cost) [t15, c15, t20, c20] = mealcost(cost); %Display results fprintf( '\nA 15 percent tip would be \$%.2f, for a total cost of \$%.2f\n' ,t15,c15); fprintf( '\nA 20%% tip would be \$%.2f, for a total cost of \$%.2f\n' ,t20,c20);

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}