Need some help with this code : A student has established the following monthly
ID: 650357 • Letter: N
Question
Need some help with this code :
A student has established the following monthly budget:
Write a program that declares a MonthlyBudget structure with member variables to hold each of these expense categories. The program should create two MonthlyBudget structure variables. The first MonthlyBudget structure variable will hold (ie., be assigned) the budget figures given above. Pass this first structure variable to a function displayBudget that will display the budget categories along with the budgeted amounts.
The second MonthlyBudget structure variable will be passed to another function getExpenses that has the user enter the amounts actually spent in each budget category during the past month. Finally, the program should then pass both structure variables to a function called compareExpenses that displays a report indicating the amount over or under budget the student spent in each category, as well as the amount over or under for the entire monthly budget.
You may design your own user-input interface but you must use a structure. The format of the monthly budgeted report should appear as similar as possible to the sample output shown below. HINT: Use the setw and right manipulators (Gaddis 7EO, Chapter 3) to right-justify dollar value outputs.
INPUT VALIDATION: Do not accept negative values.
Please make sure to include appropriate function documentation as needed (see handout on function documentation) and separate your functions with at least 1/2 inch of whitespace. You may use constant reference parameters when passing the structures to the functions mentioned above . DO NOT use global variables. Turn in your source code followed by your program output. A single test-run output is sufficient.
Budget Categories Budgeted amount Housing $ 500.00 Utilities $ 150.00 Household Expenses $ 65.00 Transportation $ 50.00 Food $ 230.00 Medical $ 30.00 Insurance $ 100.00 Entertainment $ 150.00 Clothing $ 75.00 Miscellaneous $ 50.00 *(DO NOT use arrays, pointers or an array of structs)Explanation / Answer
ADDED COMMENTS AND GIVEN SAMPLE OUTOUT TOO!!!
#include <stdio.h>
#include <string.h>
struct MonthlyBudget
{
int housing;
int utilities;
int household;
int transportation;
int food;
int medical;
int insurance;
int entertainment;
int clothing;
int miscellaneous;
};
void displayBudget(struct MonthlyBudget monthlyBudget);
void getExpenses(struct MonthlyBudget monthlyBudget,struct MonthlyBudget actualBudget);
int main( )
{
struct MonthlyBudget monthlyBudget; /* Declare monthlybudget of type Monthlybudget */
struct MonthlyBudget actualBudget; /* Declare actualBudget of type MonthlyBudget */
/* monthlybudget specification */
monthlyBudget.housing=500;
monthlyBudget.utilities=150;
monthlyBudget.household=65;
monthlyBudget.transportation=50;
monthlyBudget.food=230;
monthlyBudget.medical=30;
monthlyBudget.insurance=100;
monthlyBudget.entertainment=150;
monthlyBudget.clothing=75;
monthlyBudget.miscellaneous=150;
displayBudget(monthlyBudget); /* calling methods here */
getExpenses(monthlyBudget,actualBudget);
return 0;
}
void displayBudget(struct MonthlyBudget monthlyBudget) /* disply budget here*/
{
printf( "Housing : %d ", monthlyBudget.housing);
printf( "utilities : %d ", monthlyBudget.utilities);
printf( "household : %d ", monthlyBudget.household);
printf( "transportation : %d ",monthlyBudget.transportation);
printf( "food : %d ", monthlyBudget.food);
printf( "medical : %d ", monthlyBudget.medical);
printf( "insurance : %d ", monthlyBudget.insurance);
printf( "enterainment : %d ", monthlyBudget.entertainment);
printf( "clothing : %d ", monthlyBudget.clothing);
printf( "miscellaneous : %d ", monthlyBudget.miscellaneous);
}
void getExpenses(struct MonthlyBudget monthlyBudget,struct MonthlyBudget actualBudget)/* calculating budget here*/
{
int budgeted,spent,difference; /* reading data from user*/
printf("enter house budget");
scanf("%d",&actualBudget.housing);
printf("enter utilities budget");
scanf("%d",&actualBudget.utilities);
printf("enter household budget");
scanf("%d",&actualBudget.household);
printf("enter transportation budget");
scanf("%d",&actualBudget.transportation);
printf("enter food budget");
scanf("%d",&actualBudget.food);
printf("enter medical budget");
scanf("%d",&actualBudget.medical);
printf("enter insurance budget");
scanf("%d",&actualBudget.insurance);
printf("enter entertainment budget");
scanf("%d",&actualBudget.entertainment);
printf("enter clothing budget");
scanf("%d",&actualBudget.clothing);
printf("enter miscellaneous budget");
scanf("%d",&actualBudget.miscellaneous);
printf( "Housing : %d ", actualBudget.housing);
printf( "utilities : %d ", actualBudget.utilities);
printf( "household : %d ", actualBudget.household);
printf( "transportation : %d ",actualBudget.transportation);
printf( "food : %d ", actualBudget.food);
printf( "medical : %d ", actualBudget.medical);
printf( "insurance : %d ", actualBudget.insurance);
printf( "enterainment : %d ", actualBudget.entertainment);
printf( "clothing : %d ", actualBudget.clothing);
printf( "miscellaneous : %d ", actualBudget.miscellaneous);
printf(" Budgeted spented difference ");
printf( "Housing : %d,%d,%d ", monthlyBudget.housing,actualBudget.housing,monthlyBudget.housing-actualBudget.housing);
printf( "utilities : %d,%d,%d ", monthlyBudget.utilities,actualBudget.utilities,monthlyBudget.utilities-actualBudget.utilities);
printf( "household : %d,%d,%d ", monthlyBudget.household,actualBudget.household,monthlyBudget.household-actualBudget.household);
printf( "transportation : %d,%d,%d ",monthlyBudget.transportation,actualBudget.transportation,monthlyBudget.transportation-actualBudget.transportation);
printf( "food : %d,%d,%d ", monthlyBudget.food,actualBudget.food,monthlyBudget.food-actualBudget.food);
printf( "medical : %d,%d,%d ", monthlyBudget.medical,actualBudget.medical,monthlyBudget.medical-actualBudget.medical);
printf( "insurance : %d,%d,%d ", monthlyBudget.insurance,actualBudget.insurance,monthlyBudget.insurance-actualBudget.insurance);
printf( "enterainment : %d,%d,%d ", monthlyBudget.entertainment,actualBudget.entertainment,monthlyBudget.entertainment-actualBudget.entertainment);
printf( "clothing : %d,%d,%d ", monthlyBudget.clothing,actualBudget.clothing, monthlyBudget.clothing-actualBudget.clothing);
printf( "miscellaneous : %d,%d,%d ", monthlyBudget.miscellaneous,actualBudget.miscellaneous,monthlyBudget.miscellaneous-actualBudget.miscellaneous);
budgeted = monthlyBudget.housing+monthlyBudget.utilities+monthlyBudget.household+monthlyBudget.transportation+monthlyBudget.food+monthlyBudget.medical+monthlyBudget.insurance+monthlyBudget.entertainment+monthlyBudget.clothing+monthlyBudget.miscellaneous;
spent = actualBudget.housing+actualBudget.utilities+actualBudget.household+actualBudget.transportation+actualBudget.food+actualBudget.medical+actualBudget.insurance+actualBudget.entertainment+actualBudget.clothing+actualBudget.miscellaneous;
difference=budgeted-spent;
printf("%d,%5d,%5d ",budgeted,spent,difference);
printf(" Congratulations!! you have left with %d",difference);
}
output
Budgeted spented difference
Housing : 500, 500, 0
utilities : 150, 120, 30
household : 65, 70, -5
transportation : 50, 50, 0
food : 230, 200, 30
medical : 30, 20, 10
insurance : 100, 100, 0
enterainment : 150, 140, 10
clothing : 75, 75, 0
miscellaneous : 150, 30, 120
1500, 1305, 195
Congratulations !! you have left with 195
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.