This program should add all expenses and subtract them from the budget.
However, it's not working!
I've been working on it for hours, please help.
What am I missing? :(
#include <iostream>
#include <iomanip>
#include <cmath>
usingnamespace std;
int main()
{
//INPUT VARIABLES
float budget;
float expenses;
float total;
int count;
expenses = 0.0;
budget = 0.0;
//Input budget money
cout << "Enter the amount of money you budgeted: " << endl;
cin >> budget;
//Input expenses
for (count = 1; count <= 6; count++)
{
cout << "Enter all of your expenses for the month: " << endl;
cin >> expenses;
expenses += expenses;
}
//Processing the total money after expenses
total = budget - expenses;
//Output the total money after expenses
cout << setprecision(2) << fixed;
cout << "Your total budget after expenses: $" << total << endl;
if (total > expenses)
cout << "Your expenses are under the budget!";
else
cout << "Your expenses are over the budget!";
return 0;
}
#include <iostream>
#include <iomanip>
#include <cmath>
usingnamespace std;
int main()
{
//INPUT VARIABLES
float budget = 0.0;
float expenses = 0.0;
float total = 0.0;
float runningExpenses = 0.0; //Add a variable to maintain a running total
//Input budget money
cout << "Enter the amount of money you budgeted: " << endl;
cin >> budget;
//Input expenses
for (int count = 1; count <= 6; count++)
{
cout << "Enter all of your expenses for the month: " << endl;
cin >> expenses;
//expenses += expenses; it just double the value on the variable expenses and not running total.
runningExpenses += expenses;
}
//Processing the total money after expenses
//total = budget - expenses;
total = budget - runningExpenses;
//Output the total money after expenses
cout << setprecision(2) << fixed;
cout << "Your total budget after expenses: $" << total << endl;
if(total > runningExpenses) (budget > runningExpenses) // I gave wrong info (total > runningExpenses).
cout << "Your expenses are under the budget!";
else
cout << "Your expenses are over the budget!";
return 0;
}
Now, something to think about. If the budget is 100 and the total expenses are 100, are the expenses under or over the budget? No need to answer to me. I am just giving you a pointer on the if statements.
#include <iostream>
#include <iomanip>
#include <cmath>
usingnamespace std;
int main()
{
//INPUT VARIABLES
float budget = 0.0;
float expenses = 0.0;
float total = 0.0;
float runningExpenses = 0.0; //Add a variable to maintain a running total
//Input budget money
cout << "Enter the amount of money you budgeted: " << endl;
cin >> budget;
//Input expenses
for (int count = 1; count <= 6; count++)
{
cout << "Enter all of your expenses for the month: " << endl;
cin >> expenses;
runningExpenses += expenses;
}
//Processing the total money after expenses
total = budget - runningExpenses;
//Output the total money after expenses
cout << setprecision(2) << fixed;
cout << "Your total budget after expenses: $" << total << endl;
if (budget > runningExpenses)
cout << "Your expenses are under the budget!";
elseif (budget < runningExpenses)
cout << "Your expenses are over the budget!";
else
cout << "You're breaking even between your expenses and budget!\n";
return 0;
}