Untitled
// Julia Knowles // CSC 7131 - Assignment 1 // Project: Basic Personal Finance Tracker // adding standard header files #include <stdio.h> #include <stdlib.h> // Declaring and initializing the global variables and constants that // we'll need to use across multiple functions... float money_in; const float tax_rate = .05; float net_money_in; float money_out; float final_balance; char character = 'five'; int income(); int expenses(); int multiple_expenses(); int balance(); void summary(); // Setting up the main function to call the various functions we want to run... int main() { income(); expenses(); balance(); summary(); return 0; } // Building an income function that asks the user to enter their // gross income. It then takes the user's input and calculates the // net income for the day using the tax_rate constant... int income() { printf("Enter your gross income for the day: \n"); scanf("%f", &money_in); // Preventing negative inputs for income. if (money_in >= 0){ net_money_in = money_in * (1 - tax_rate); } else { printf("Let's try that again with a positive number! \n"); income(); } return 0; } float expense_input; float baseline_float = 589.73; int baseline_int = 589; // Building an expenses function that asks the user to enter the amount // of the first purchase they made that day. int expenses() { printf("Write the cost of each item you purchased today and then press 'Enter': \n"); scanf("%f", &expense_input); multiple_expenses(); // Using a while loop to determine when the user has finished entering // their expenses for the day and to add each new expense to the running total. return 0; } int multiple_expenses() { while ((expense_input != 0) && (expense_input != character)) { if (expense_input > 0){ money_out = money_out + expense_input; printf("How much did your next purchase cost? When finished, type '0' and press 'Enter': \n"); scanf("%f", &expense_input); } else if (expense_input < 0) { printf("Let's try that again with a positive number! Or enter '0' if you're done.\n"); expenses(); } else { return 0; } } return 0; } // Calculating the balance remaining using the net money earned (after taxes) // and the total expenses paid. int balance() { final_balance = net_money_in - money_out; return 0; } // Printing a formatted summary including the user's income, expenses, // and balance for the day. void summary() { printf("Net income: %.2f\n", net_money_in); printf("Total expenses: %.2f\n", money_out); printf("Final balance: %.2f\n", final_balance); }
Leave a Comment