51 lines
2.0 KiB
C
51 lines
2.0 KiB
C
// Nicholas Pease
|
|
// 14 FEB 2023
|
|
// Monthly Budget Calculator
|
|
|
|
#include <stdio.h>
|
|
#define FIXED_ADDITIONAL_MONTHLY_COSTS 581.99
|
|
#define NUMBER_OF_INPUTS 6
|
|
|
|
int main() {
|
|
// Declare Variables
|
|
|
|
// double array: inputs[]: Stores all numeric input information
|
|
/*
|
|
0: Monthly Expense Goal (USD)
|
|
1: Rent Expenses Monthly (USD)
|
|
2: Utilities Expenses Monthly (USD)
|
|
3: Transportation Expenses Monthly (USD)
|
|
4: Food Costs Expenses Monthly (USD)
|
|
5: Car Payment (As set by #define above)
|
|
*/
|
|
// double totalExpenses: Stores the total expenditure
|
|
double inputs[6], totalExpenses;
|
|
// char name: Stores entered name
|
|
char name[20];
|
|
// char array inputString: Stores all input prompt string. Also corresponds to inputs in how data is stored
|
|
char *inputStrings[6] = {"Monthly Expense Goal", "Rent","Utilities", "Transportation","Food Costs","Car Payment"};
|
|
// init car payment to constant
|
|
inputs[5] = FIXED_ADDITIONAL_MONTHLY_COSTS;
|
|
|
|
// Prompt for information
|
|
printf("Please enter your name: ");
|
|
fgets(name, 20, stdin);
|
|
for (int i = 0; i < NUMBER_OF_INPUTS-1; i++) {
|
|
printf("Enter %s (USD): ",inputStrings[i]);
|
|
scanf(" %lf",&inputs[i]);
|
|
}
|
|
|
|
// end initial inputs, generate and print budget chart
|
|
printf("\nBudget Chart for %s",name);
|
|
printf("%-30s %-30s %-30s\n","Expense:","Amount $","Percent %");
|
|
for (int i=1; i< NUMBER_OF_INPUTS; i++) {totalExpenses+=inputs[i];}
|
|
for (int i=1; i < NUMBER_OF_INPUTS; i++) {
|
|
printf("%-30s %-30.2lf %-30.2lf\n",inputStrings[i],inputs[i],(inputs[i]/totalExpenses)*100);
|
|
}
|
|
double leftoverAmount = inputs[0] - totalExpenses;
|
|
printf("\n%-30s %-30.2lf\n",inputStrings[0],inputs[0]);
|
|
printf("%-30s %-30.2lf\n","Total Expenses",totalExpenses);
|
|
printf("%-30s %-30.2lf\n","Leftover amount",leftoverAmount);
|
|
printf("%s\n", (leftoverAmount > inputs[0]/5)? "Good job. You are saving enough!": "Try to save more!");
|
|
return 0;
|
|
} |