Advertisement
Guest User

Untitled

a guest
Dec 17th, 2018
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 4.51 KB | None | 0 0
  1. #define _CRT_SECURE_NO_WARNINGS
  2. #include <stdio.h>
  3. #include "functions.h"// allows functions.h to access functions.c
  4. //Below all constants are defined and set
  5. #define annual_fee 9250
  6. #define placement_fee 1850
  7. #define placement_maintance 2350
  8. #define maintance_loan 8700
  9. #define RPI 0.033
  10. #define interest_rate 0.03
  11. #define MIN_salary 20000
  12. #define MAX_salary 50000
  13. #define increment 5000
  14. #define sal_cut_off 25000
  15. #define ANN_sal_inc 0.03
  16. #define pay_back_percentage 0.09
  17. #define max_months 360
  18.  
  19.  
  20. int grad_year, total_loan, counted_months;// integer values being used
  21. double loan_inc_interest, loan_balance[360], monthly_rep[360],monthly_int[360], monthly_int_rte[360], starting_sal, final_sal[360], con_income[360], salary; // float values being used
  22.  
  23. void graduation_date(int courselength, int placement, int MM, int YYYY) {
  24.     //the graduation date of the use is calculated dependant on if they are undertaking a placement year
  25.     if (placement == 'Y' || placement == 'y') {
  26.         YYYY++;
  27.         grad_year = YYYY + courselength;
  28.         printf("Your graduation date is 06/%d", grad_year);
  29.         //if the user is undertaking a placement year, the year they entered is being increased by due to this and added to courselength
  30.     }
  31.     else if (placement == 'N' || placement == 'n') {
  32.         grad_year = YYYY + courselength;
  33.         printf("Your graduation date is 06/%d", grad_year);
  34.         //if the user is not undertaking a placement year the year they entered will be added to their courselength
  35.     }
  36. }
  37.  
  38. void payment_date() {
  39.     //calculating first payment date
  40.     grad_year++;
  41.     printf("\nYour first payment year will be in 04/%d", grad_year);
  42.     //adds one year to the grad year
  43. }
  44.  
  45. void valueof_loan(char placement, int courselength) {
  46.     //value of the users loan as they leave university is being calculated
  47.     if (placement == 'y' || placement == 'Y') {
  48.         //will run if the user is undertaking a placement year
  49.         total_loan = (courselength*annual_fee) + placement_fee + placement_maintance + (courselength*maintance_loan);
  50.         printf("\nThe total value of your loan without interest is %d", total_loan);//total loan before interest
  51.        
  52.         for (int year = 0; year < 2; year++) {//This is for the two years before the placement year
  53.             loan_inc_interest = (loan_inc_interest + (annual_fee + maintance_loan))*(1 + RPI + interest_rate);//Loan counter will take the previous years loan with interest and add maintance loan and tution fees on, and multiply by 1.063(RPI+interest rate)
  54.             printf("\nThe value of your loan including interest after %d year is %f\n", year + 1, loan_inc_interest);//outputs loan including interst after the year, until two years
  55.         }
  56.  
  57.         //assume the placement year is after the second year
  58.         loan_inc_interest = (loan_inc_interest + (placement_fee + placement_maintance))*(1 + RPI + interest_rate);//during placement year, miantance loan and tution fee are replaced with placement maintance and
  59.         printf("\nThe value of your loan including interest after undertaking a placement year is %f", loan_inc_interest);
  60.  
  61.         for (int year = 2; year < courselength; year++) {
  62.             loan_inc_interest = (loan_inc_interest + (annual_fee + maintance_loan))*(1 + RPI + interest_rate);
  63.             printf("\nThe value of your loan including interest after %d year is %f\n", year + 1, loan_inc_interest);
  64.         }
  65.  
  66.     }
  67.     else if (placement == 'n' || placement == 'N') {
  68.         for (int n = 0; n <= courselength; n++) {
  69.             loan_inc_interest = (loan_inc_interest + (annual_fee + maintance_loan))*(1 + RPI + interest_rate);
  70.             printf("\n%f\n", loan_inc_interest);
  71.         }
  72.  
  73.     }
  74. }
  75. void Salary_calculation() {
  76.     salary = MIN_salary;
  77.     FILE *csv;
  78.     csv = fopen("loancalc.csv", "w");
  79.  
  80.  
  81.     FILE *txt;
  82.     txt = fopen("loancalc.txt", "w");
  83.     fclose(txt);
  84.     for (MIN_salary; salary <= MAX_salary; salary = salary + increment) {
  85.         double new_salary[361];//makes first value of array equal to salary
  86.         new_salary[0] = salary;//
  87.         counted_months = 0;
  88.  
  89.         while (counted_months < max_months) {
  90.             counted_months++;
  91.             printf("%d", counted_months);
  92.             if (counted_months % 12 == 0) {
  93.                 new_salary[counted_months] = new_salary[(counted_months)-1] + (new_salary[(counted_months)-1] * (RPI + ANN_sal_inc));
  94.             }
  95.             else {
  96.                 new_salary[counted_months] = new_salary[(counted_months)-1];
  97.  
  98.             }
  99.  
  100.         }
  101.         fprintf(csv, "SALARY: ,");
  102.         for (int counter = 0; counter <= counted_months; counter++) {
  103.             fprintf(csv, "%f,", new_salary[counter]);
  104.         }
  105.         fprintf(csv, "\n");
  106.  
  107.  
  108.  
  109.  
  110.  
  111.         FILE *txt;
  112.         txt = fopen("loancalc.txt", "a");
  113.         fprintf(txt, "\nfinal salary: %f", new_salary[counted_months]);
  114.         fclose(txt);
  115.     }
  116.  
  117.  
  118. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement