Advertisement
JKattackk

Assignment3B

Feb 27th, 2020
816
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 1.71 KB | None | 0 0
  1. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  2. % Course: ENCMP 100
  3. % Assignment: 3B
  4. % Name:
  5. % CCID:
  6. % U of A ID:
  7. %
  8. % Acknowledgements:
  9. % I refered to the MatLab documentation while writing.
  10. %
  11. % Description:
  12. % This program calculates the minimum monthly deposit to reach the goal of
  13. % total tuition cost by year 18.
  14. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  15. clc;
  16. clear;
  17. baseCost = 0;
  18. while baseCost == 0
  19.    program = input('Select a program: 1. Arts; 2. Science; 3. Engineering: ');         %Switch for program number, catches invalid numerical
  20.                                                                                        %inputs but does not catch Strings or chars
  21.    switch program
  22.        case 1
  23.            baseCost = 6000;
  24.        case 2
  25.            baseCost = 6500;
  26.        case 3
  27.            baseCost = 7000;
  28.        otherwise
  29.            disp('Invalid input');
  30.    end
  31. end
  32. totCost = 0;
  33. 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)
  34.     if i > 18
  35.         totCost = totCost + baseCost;
  36.     end
  37.     baseCost = baseCost*1.0575;
  38. end
  39. fprintf('The 4-year tuition fee is $%.2f\n', totCost);
  40. deposit = 40;                        %Initial deposit, 50-10 because we add 10 at the start of the loop before calcilating.
  41. bal = 0;
  42. while(bal < totCost)                 %Until the final balance is enough to cover the cost of tuition the loop
  43.                                      %will continue adding 10 to the initial balance each time
  44.     deposit = deposit + 10;
  45.     bal = 2000;
  46.     for i=1:216
  47.         bal = bal*1.005 + deposit;
  48.     end
  49. end
  50. 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