0% found this document useful (0 votes)
37 views2 pages

Personal Finance Manager in C

This C program defines structures to store financial transaction and user data. It includes functions to add transactions, calculate a budget, and display a financial report. The main function initializes a user, displays a menu, and allows the user to add transactions, view their budget, or see a report by selecting different options. Transaction data is stored in the user structure and updated based on the transaction type.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
37 views2 pages

Personal Finance Manager in C

This C program defines structures to store financial transaction and user data. It includes functions to add transactions, calculate a budget, and display a financial report. The main function initializes a user, displays a menu, and allows the user to add transactions, view their budget, or see a report by selecting different options. Transaction data is stored in the user structure and updated based on the transaction type.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

#include <stdio.

h>
#include <stdlib.h>
#include <string.h>

// Define structures to store financial data


struct Transaction {
char description[100];
float amount;
};

struct User {
float income;
float expenses;
float savings;
float investments;
struct Transaction transactions[50];
int numTransactions;
};

// Function prototypes
void displayMenu();
void addTransaction(struct User *user, char *type);
void calculateBudget(struct User *user);
void displayReport(struct User *user);

int main() {
struct User user = {0, 0, 0, 0, {}, 0};
int choice;

do {
displayMenu();
printf("Enter your choice: ");
scanf("%d", &choice);

switch (choice) {
case 1:
addTransaction(&user, "income");
break;
case 2:
addTransaction(&user, "expenses");
break;
case 3:
addTransaction(&user, "savings");
break;
case 4:
addTransaction(&user, "investments");
break;
case 5:
calculateBudget(&user);
break;
case 6:
displayReport(&user);
break;
case 0:
printf("Exiting the Personal Finance Manager. Goodbye!\n");
break;
default:
printf("Invalid choice. Please try again.\n");
}
} while (choice != 0);

return 0;
}

void displayMenu() {
printf("\nPersonal Finance Manager Menu\n");
printf("1. Add Income\n");
printf("2. Add Expenses\n");
printf("3. Add Savings\n");
printf("4. Add Investments\n");
printf("5. Calculate Budget\n");
printf("6. Display Financial Report\n");
printf("0. Exit\n");
}

void addTransaction(struct User *user, char *type) {


struct Transaction newTransaction;
printf("Enter %s description: ", type);
scanf("%99s", [Link]); // Limit to 99 characters
printf("Enter %s amount: ", type);
scanf("%f", &[Link]);

// Update user data based on the transaction type


if (strcmp(type, "income") == 0) {
user->income += [Link];
} else if (strcmp(type, "expenses") == 0) {
user->expenses += [Link];
} else if (strcmp(type, "savings") == 0) {
user->savings += [Link];
} else if (strcmp(type, "investments") == 0) {
user->investments += [Link];
}

// Add the transaction to the user's transaction history


user->transactions[user->numTransactions++] = newTransaction;

printf("Transaction added successfully!\n");


}

void calculateBudget(struct User *user) {


float budget = user->income - user->expenses;
printf("Budget: %.2f\n", budget);
}

void displayReport(struct User *user) {


printf("\nFinancial Report\n");
printf("Income: %.2f\n", user->income);
printf("Expenses: %.2f\n", user->expenses);
printf("Savings: %.2f\n", user->savings);
printf("Investments: %.2f\n", user->investments);

// Display transaction history


printf("\nTransaction History\n");
for (int i = 0; i < user->numTransactions; ++i) {
printf("%s: %.2f\n", user->transactions[i].description, user-
>transactions[i].amount);
}}

You might also like