# hw4p3 - fprintf'The cost for month.0f is.2f\n,n,mtotal end...

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

clear; clc; c n = 0; TotCost = 0; TotMins = 0; nexceed = 0; nmonths = 0; minrate = 0; mins = 0; excost = 0; e 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:'); b 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;
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: fprintf('The cost for month %.0f is: %.2f\n',n,mtotal); end e avgcost = TotCost / nmonths; avgmins = TotMins / nmonths; avgcostpmin = TotCost / TotMins; a 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);...
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