Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define _CRT_SECURE_NO_WARNINGS
- #include <stdio.h>
- #include "functions.h"// allows functions.h to access functions.c
- //Below all constants are defined and set
- #define annual_fee 9250
- #define placement_fee 1850
- #define placement_maintance 2350
- #define maintance_loan 8700
- #define RPI 0.033
- #define interest_rate 0.03
- #define MIN_salary 20000
- #define MAX_salary 50000
- #define increment 5000
- #define sal_cut_off 25000
- #define ANN_sal_inc 0.03
- #define pay_back_percentage 0.09
- #define max_months 360
- int grad_year, total_loan, counted_months;// integer values being used
- 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
- void graduation_date(int courselength, int placement, int MM, int YYYY) {
- //the graduation date of the use is calculated dependant on if they are undertaking a placement year
- if (placement == 'Y' || placement == 'y') {
- YYYY++;
- grad_year = YYYY + courselength;
- printf("Your graduation date is 06/%d", grad_year);
- //if the user is undertaking a placement year, the year they entered is being increased by due to this and added to courselength
- }
- else if (placement == 'N' || placement == 'n') {
- grad_year = YYYY + courselength;
- printf("Your graduation date is 06/%d", grad_year);
- //if the user is not undertaking a placement year the year they entered will be added to their courselength
- }
- }
- void payment_date() {
- //calculating first payment date
- grad_year++;
- printf("\nYour first payment year will be in 04/%d", grad_year);
- //adds one year to the grad year
- }
- void valueof_loan(char placement, int courselength) {
- //value of the users loan as they leave university is being calculated
- if (placement == 'y' || placement == 'Y') {
- //will run if the user is undertaking a placement year
- total_loan = (courselength*annual_fee) + placement_fee + placement_maintance + (courselength*maintance_loan);
- printf("\nThe total value of your loan without interest is %d", total_loan);//total loan before interest
- for (int year = 0; year < 2; year++) {//This is for the two years before the placement year
- 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)
- 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
- }
- //assume the placement year is after the second year
- 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
- printf("\nThe value of your loan including interest after undertaking a placement year is %f", loan_inc_interest);
- for (int year = 2; year < courselength; year++) {
- loan_inc_interest = (loan_inc_interest + (annual_fee + maintance_loan))*(1 + RPI + interest_rate);
- printf("\nThe value of your loan including interest after %d year is %f\n", year + 1, loan_inc_interest);
- }
- }
- else if (placement == 'n' || placement == 'N') {
- for (int n = 0; n <= courselength; n++) {
- loan_inc_interest = (loan_inc_interest + (annual_fee + maintance_loan))*(1 + RPI + interest_rate);
- printf("\n%f\n", loan_inc_interest);
- }
- }
- }
- void Salary_calculation() {
- salary = MIN_salary;
- FILE *csv;
- csv = fopen("loancalc.csv", "w");
- FILE *txt;
- txt = fopen("loancalc.txt", "w");
- fclose(txt);
- for (MIN_salary; salary <= MAX_salary; salary = salary + increment) {
- double new_salary[361];//makes first value of array equal to salary
- new_salary[0] = salary;//
- counted_months = 0;
- while (counted_months < max_months) {
- counted_months++;
- printf("%d", counted_months);
- if (counted_months % 12 == 0) {
- new_salary[counted_months] = new_salary[(counted_months)-1] + (new_salary[(counted_months)-1] * (RPI + ANN_sal_inc));
- }
- else {
- new_salary[counted_months] = new_salary[(counted_months)-1];
- }
- }
- fprintf(csv, "SALARY: ,");
- for (int counter = 0; counter <= counted_months; counter++) {
- fprintf(csv, "%f,", new_salary[counter]);
- }
- fprintf(csv, "\n");
- FILE *txt;
- txt = fopen("loancalc.txt", "a");
- fprintf(txt, "\nfinal salary: %f", new_salary[counted_months]);
- fclose(txt);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement