ps6solnsF06

ps6solnsF06 - %Engineering 6, Fall 2006, Problem 6.1...

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

View Full Document Right Arrow Icon
%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'
Background image of page 1

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

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 3

ps6solnsF06 - %Engineering 6, Fall 2006, Problem 6.1...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online