Question: Do some modification to the code , after the program has read all the information regarding user savings and expenses for the whole year, the
Do some modification to the code , after the program has read all the information regarding user savings and expenses for the whole year, the program should allow user to select and print the total expenses of a particular month
same as the picture
modify to this code :
#include
#define year 12
char *month[12] =
{"Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"};
double water_usage[12];
double electricity_usage[12];
double saving[12];
void calculate_monthly_expenses();
void calculate_yearly_expenses();
double calculate_electric_bill(double kWh);
double calculate_water_bill(double m);
double calculate_epf();
int main()
{
calculate_monthly_expenses();
calculate_yearly_expenses();
}
double calculate_electric_bill(double kWh)
{
double electric_bill;
if (kWh
electric_bill = 3;
else if (kWh
electric_bill = kWh * 0.218;
else if (kWh
electric_bill = ((kWh - 200) * 0.334) + 43.6;
else if (kWh
electric_bill = ((kWh - 300) * 0.4) + 77;
else if (kWh
electric_bill = ((kWh - 400) * 0.402) + 117;
else if (kWh
electric_bill = ((kWh - 500) * 0.416) + 158;
else if (kWh
electric_bill = ((kWh - 600) * 0.426) + 200.6;
else if (kWh
electric_bill = ((kWh - 700) * 0.437) + 244.3;
else if (kWh
electric_bill = ((kWh - 800) * 0.453) + 289.6;
else
electric_bill = ((kWh - 900) * 0.454) + 334.9;
return electric_bill;
}
double calculate_water_bill(double m)
{
double water_bill;
if (m == 0)
water_bill = 6;
else if (m
water_bill = m * 0.57;
else if (m
water_bill = ((m - 20) * 1.03) + 11.4;
else
water_bill = ((m - 35) * 2) + 28.85;
return water_bill;
}
void calculate_monthly_expenses()
{
double monthly_expenses = 0.0, epf, extra_expenses, electric_bill, water_bill;
int i;
epf = calculate_epf();
for(i=0; i
{
printf("%s ", month[i]);
printf("Electricity Usage: ");
scanf_s("%lf", &electricity_usage[i]);
printf("Water Usage: ");
scanf_s("%lf", &water_usage[i]);
printf("Total Amount to save: ");
scanf_s("%lf", &saving[i]);
electric_bill = calculate_electric_bill(electricity_usage[i]);
water_bill = calculate_water_bill(water_usage[i]);
extra_expenses = 2450 - epf - saving[i] - electric_bill - water_bill - 300
- 75;
monthly_expenses = electric_bill + water_bill + 300 + 75;
printf(" Total Expenses for %s: %.2lf ", month[i], monthly_expenses);
printf("Money left to spend: %.2lf ", extra_expenses);
printf("------------------------------ ");
}
}
void calculate_yearly_expenses()
{
double yearly_expenses = 0.0, total_epf, total_saving = 0.0, epf, electric_bill,
water_bill;
int i;
epf = calculate_epf();
total_epf = epf * 12;
printf(" ------------------------------------------------ ");
for (i = 0; i
{
electric_bill = calculate_electric_bill(electricity_usage[i]);
water_bill = calculate_water_bill(water_usage[i]);
yearly_expenses += electric_bill + water_bill + 300 + 75;
total_saving += saving[i];
}
printf(" Yearly expenses: %.2lf", yearly_expenses);
printf(" Total amount of EPF: %.2lf", total_epf);
printf(" Total amount of savings: %.2lf", total_saving);
}
double calculate_epf()
{
double epf;
epf = 2450.0 * 7 / 100;
return epf;
}
- x CA C:WINDOWS\system32\cmd.exe Select Month: May Electricity usage : RM 45.00 Water consumption: RM 8.00 Internet usage: RM 75.00 House rent: RM300.00 Savings : RM 60.00 Press any key to continue
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
