Here's a simplified C program that calculates the expenditure of everyday life to run a house based on a monthly salary and a savings goal of 50%:
Household Expenditure Calculator
```
#include <stdio.h>
// Define structure for household expenses
typedef struct {
float rent;
float utilities;
float groceries;
float transportation;
float entertainment;
float miscellaneous;
} HouseholdExpenses;
// Function to calculate total expenses
float calculateTotalExpenses(HouseholdExpenses expenses) {
return expenses.rent + expenses.utilities + expenses.groceries + expenses.transportation + expenses.entertainment + expenses.miscellaneous;
}
// Function to calculate savings
float calculateSavings(float salary) {
return salary * 0.5;
}
int main() {
float salary;
printf("Enter your monthly salary: ");
scanf("%f", &salary);
HouseholdExpenses expenses;
printf("Enter your monthly expenses:\n");
printf("Rent: ");
scanf("%f", &expenses.rent);
printf("Utilities: ");
scanf("%f", &expenses.utilities);
printf("Groceries: ");
scanf("%f", &expenses.groceries);
printf("Transportation: ");
scanf("%f", &expenses.transportation);
printf("Entertainment: ");
scanf("%f", &expenses.entertainment);
printf("Miscellaneous: ");
scanf("%f", &expenses.miscellaneous);
float totalExpenses = calculateTotalExpenses(expenses);
float savings = calculateSavings(salary);
printf("\nSummary:\n");
printf("Monthly Salary: %.2f\n", salary);
printf("Total Expenses: %.2f\n", totalExpenses);
printf("Savings: %.2f\n", savings);
if (totalExpenses > salary - savings) {
printf("\nWarning: Your expenses exceed your available income!\n");
} else {
printf("\nCongratulations! You have enough income to cover your expenses and savings.\n");
}
return 0;
}
```
This program demonstrates the following concepts:
1. *Household expenses structure*: A structure to represent household expenses with attributes like rent, utilities, groceries, transportation, entertainment, and miscellaneous.
2. *Total expenses calculation*: A function to calculate the total expenses based on the household expenses structure.
3. *Savings calculation*: A function to calculate the savings based on a 50% savings goal.
4. *Income and expense comparison*: A check to ensure that the total expenses do not exceed the available income after savings.
Note that this program is a simplified example and does not cover real-world complexities like:
- Variable expenses and income
- Debt and credit management
- Long-term savings and investment goals
- Inflation and cost-of-living adjustments
To make this program more comprehensive and useful, you would need to consider these factors and add additional features and functionality.
No comments:
Post a Comment