Anyone help me with this Failure.
May 7, 2014 at 2:53am UTC
Why happens this failure?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136
#include <iostream>
#include <iomanip>
#include <string>
using namespace std;
struct Budget //declare a global type
{
double housing;
double utilities;
double household_exp;
double transportation;
double food;
double medical;
double insurance;
double entertainment;
double clothing;
double misc;
};
Budget set_budget()
{
Budget set = {500.00, 150.00, 65.00, 50.00, 250.00, 30.00, 100.00,
150.00, 75.00, 50.00};
return (set);
}
Budget get_spent() //returns a budget spent structure
{
Budget spent;
cout<<"Enter in Housing Expense: " ;
cin>>spent.housing;
cout<<"Enter in Utilities Expense: " ;
cin>>spent.utilities;
cout<<"Enter in Household Expenses: " ;
cin>>spent.household_exp;
cout<<"Enter in Transportation Expense: " ;
cin>>spent.transportation;
cout<<"Enter in Food Expense: " ;
cin>>spent.food;
cout<<"Enter in Medical Expense: " ;
cin>>spent.medical;
cout<<"Enter in Entertainment Expense: " ;
cin>>spent.entertainment;
cout<<"Enter in Clothing Expense: " ;
cin>>spent.clothing;
cout<<"Enter in Miscellaneous Expenses: " ;
cin>>spent.misc;
return spent;
}
Budget calculate_spent()
{
Budget total;
Budget spent;
Budget fixed;
fixed = set_budget();
spent = get_spent();
total.housing = (fixed.housing - spent.housing);
total.utilities = (fixed.utilities - spent.utilities);
total.household_exp = (fixed.household_exp - spent.household_exp);
total.transportation = (fixed.transportation - spent.transportation);
total.food = (fixed.food - spent.food);
total.medical = (fixed.medical - spent.medical);
total.entertainment = (fixed.entertainment - spent.entertainment);
total.clothing = (fixed.clothing - spent.clothing);
total.misc = (fixed.misc - spent.misc);
return (total);
}
void output()
{
Budget fixed;
Budget set_budget;
fixed = set_budget;
Budget spent;
Budget get_spent;
spent = get_spent;
Budget total;
Budget calculate_spent;
total = calculate_spent;
Budget difference = (set_budget, get_spent);
cout<<"Category\t\t" <<"Budgeted\t" <<"Spent\t" <<"Over(-)/Under\n"
"------------------------------------------------------------\n"
"Housing\t\t" <<fixed.housing<<"\t" <<spent.housing<<"\t\t\n"
"Utilities\t\t" <<fixed.utilities<<"\t" <<spent.utilities<<"\t\t\n"
"Household_Exp\t\t" <<fixed.household_exp<<"\t" <<spent.household_exp<<"\t\t\n"
"Transportation\t\t" <<fixed.transportation<<"\t" <<spent.transportation<<"\t\t\n"
"Food\t\t" <<fixed.food<<"\t" <<spent.food<<"\t\t\n"
"Medical\t\t" <<fixed.medical<<"\t" <<spent.medical<<"\t\t\n"
"Entertainment\t\t" <<fixed.entertainment<<"\t" <<spent.entertainment<<"\t\t\n"
"Clothing\t\t" <<fixed.clothing<<"\t" <<spent.clothing<<"\t\t\n"
"Miscellaneous\t\t" <<fixed.misc<<"\t" <<spent.misc<<"\t\t" ;
}
int main()
{
set_budget();
calculate_spent();
output();
return 0;
}
May 7, 2014 at 4:19am UTC
Are you referring to line 104:
Budget difference = (set_budget, get_spent);
? Is that supposed to be a function that returns struct or a variable that has the different of two budget structs? Without it the program compiles and run.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138
#include <iostream>
#include <iomanip>
#include <string>
using namespace std;
struct Budget //declare a global type
{
double housing;
double utilities;
double household_exp;
double transportation;
double food;
double medical;
double insurance;
double entertainment;
double clothing;
double misc;
};
Budget set_budget()
{
Budget set = {500.00, 150.00, 65.00, 50.00, 250.00, 30.00, 100.00,
150.00, 75.00, 50.00};
return (set);
}
Budget get_spent() //returns a budget spent structure
{
Budget spent;
cout<<"Enter in Housing Expense: " ;
cin>>spent.housing;
cout<<"Enter in Utilities Expense: " ;
cin>>spent.utilities;
cout<<"Enter in Household Expenses: " ;
cin>>spent.household_exp;
cout<<"Enter in Transportation Expense: " ;
cin>>spent.transportation;
cout<<"Enter in Food Expense: " ;
cin>>spent.food;
cout<<"Enter in Medical Expense: " ;
cin>>spent.medical;
cout<<"Enter in Entertainment Expense: " ;
cin>>spent.entertainment;
cout<<"Enter in Clothing Expense: " ;
cin>>spent.clothing;
cout<<"Enter in Miscellaneous Expenses: " ;
cin>>spent.misc;
return spent;
}
Budget calculate_spent()
{
Budget total;
Budget spent;
Budget fixed;
fixed = set_budget();
spent = get_spent();
total.housing = (fixed.housing - spent.housing);
total.utilities = (fixed.utilities - spent.utilities);
total.household_exp = (fixed.household_exp - spent.household_exp);
total.transportation = (fixed.transportation - spent.transportation);
total.food = (fixed.food - spent.food);
total.medical = (fixed.medical - spent.medical);
total.entertainment = (fixed.entertainment - spent.entertainment);
total.clothing = (fixed.clothing - spent.clothing);
total.misc = (fixed.misc - spent.misc);
return (total);
}
void output()
{
Budget fixed;
Budget set_budget;
fixed = set_budget;
Budget spent;
Budget get_spent;
spent = get_spent;
Budget total;
Budget calculate_spent;
total = calculate_spent;
// what is the point of this line?
//Budget difference = (set_budget, get_spent);
cout << std::fixed << setprecision(2); // makes it only print out dollars $0.00 and fixed so you don't get scientific notation
cout << "Category\t\t" <<"Budgeted\t" <<"Spent\t" <<"Over(-)/Under\n"
"------------------------------------------------------------\n"
"Housing\t\t" <<fixed.housing<<"\t" <<spent.housing<<"\t\t\n"
"Utilities\t\t" <<fixed.utilities<<"\t" <<spent.utilities<<"\t\t\n"
"Household_Exp\t\t" <<fixed.household_exp<<"\t" <<spent.household_exp<<"\t\t\n"
"Transportation\t\t" <<fixed.transportation<<"\t" <<spent.transportation<<"\t\t\n"
"Food\t\t" <<fixed.food<<"\t" <<spent.food<<"\t\t\n"
"Medical\t\t" <<fixed.medical<<"\t" <<spent.medical<<"\t\t\n"
"Entertainment\t\t" <<fixed.entertainment<<"\t" <<spent.entertainment<<"\t\t\n"
"Clothing\t\t" <<fixed.clothing<<"\t" <<spent.clothing<<"\t\t\n"
"Miscellaneous\t\t" <<fixed.misc<<"\t" <<spent.misc<<"\t\t" ;
}
int main()
{
set_budget();
calculate_spent();
output();
return 0;
}
Topic archived. No new replies allowed.