Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- % Course: ENCMP 100
- % Assignment: 3B
- % Name:
- % CCID:
- % U of A ID:
- %
- % Acknowledgements:
- % I refered to the MatLab documentation while writing.
- %
- % Description:
- % This program calculates the minimum monthly deposit to reach the goal of
- % total tuition cost by year 18.
- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- clc;
- clear;
- baseCost = 0;
- while baseCost == 0
- program = input('Select a program: 1. Arts; 2. Science; 3. Engineering: '); %Switch for program number, catches invalid numerical
- %inputs but does not catch Strings or chars
- switch program
- case 1
- baseCost = 6000;
- case 2
- baseCost = 6500;
- case 3
- baseCost = 7000;
- otherwise
- disp('Invalid input');
- end
- end
- totCost = 0;
- for i = 1:22 %Calculating the total cost for the 4 year program at the end of the 18 year saving period (year 19-22)
- if i > 18
- totCost = totCost + baseCost;
- end
- baseCost = baseCost*1.0575;
- end
- fprintf('The 4-year tuition fee is $%.2f\n', totCost);
- deposit = 40; %Initial deposit, 50-10 because we add 10 at the start of the loop before calcilating.
- bal = 0;
- while(bal < totCost) %Until the final balance is enough to cover the cost of tuition the loop
- %will continue adding 10 to the initial balance each time
- deposit = deposit + 10;
- bal = 2000;
- for i=1:216
- bal = bal*1.005 + deposit;
- end
- end
- fprintf('You will need to save $%.2f each month to reach the goal\n', deposit);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement