14W-CF 02082011 Campos,Tyler HW4 78

14W-CF 02082011 Campos,Tyler HW4 78

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
Matlab Code clear; clc; n = 0; TotCost = 0; TotMins = 0; nexceed = 0; nmonths = 0; minrate = 0; mins = 0; excost = 0; minrate = input('Enter monthly rate:'); mins = input('Enter number of minutes included in plan: '); excost = input('Enter amount charged per excess minute:'); nmonths = input('\nEnter number of months you would like to calculate your phone bill in:'); while n < nmonths; n = n+1; fprintf('\nFor month %.0f,',n); minsused = input('Enter number of minutes used:'); if minsused > mins; minsover = minsused - mins; excesscost = minsover * excost; mtotal = excesscost + minrate; nexceed = nexceed+1; else mtotal = minrate; end TotCost = TotCost + mtotal; TotMins = TotMins + minsused; fprintf('The cost for month %.0f is:
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: %.2f\n',n,mtotal); end avgcost = TotCost / nmonths; avgmins = TotMins / nmonths; avgcostpmin = TotCost / TotMins; fprintf('\nThe total cost for the %.0f months was: %.2f', nmonths,TotCost) fprintf('\nThe average cost per month was: %.2f',avgcost); fprintf('\nThe total minutes used was: %.0f',TotMins); fprintf('\nThe average amount of minutes used per month was: %.0f',avgmins); fprintf('\nThe average cost per minute was: %.2f',avgcostpmin); fprintf('\nYou exceeded the included minutes in %.0f of the %.0f months.\n',nexceed,nmonths); 14W-CF 02/08/2011 Campos,Tyler HW4 7/8 Wednesday, February 09, 2011 4:28 PM HW4 Page 1...
View Full Document

This note was uploaded on 09/19/2011 for the course ENGE 1114 taught by Professor Twknott during the Fall '06 term at Virginia Tech.

Ask a homework question - tutors are online