Need help with errors

I edited my code to use a do while loop and to make a text file but i am having issues to understand the two errors I have

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
  #include <iostream>
#include <iomanip>
#include <cmath>
#include <fstream>

using namespace std;

//number of catagories 
const int NUM_EXP = 10;
//the monthly income
const int EXP_AMT = 1500;

struct MonthlyBudget { 
int housing; 
int utilities; 
int householdExpenses; 
int transporation; 
int food;
int medical;
int insurance;
int entertainment;
int clothing;
int miscellaneous;
int gross;
int under;
int over;
};

int main()
 {
do
{
MonthlyBudget actual;
cout << "Enter amount for housing ";
  cin >> actual.housing;
  cout << "Enter amount for utilities ";
  cin >> actual.utilities;
  cout << "Enter amount for household expenses ";
  cin >> actual.householdExpenses;
  cout << "Enter amount for transportation ";
  cin >> actual.transporation;
  cout << "Enter amount for food ";
  cin >> actual.food;
  cout << "Enter amount for medical ";
  cin >> actual.medical;
  cout << "Enter amount for insurance ";
  cin >> actual.insurance;
  cout << "Enter amount for entertainment ";
  cin >> actual.entertainment;
  cout << "Enter amount for clothing ";
  cin >> actual.clothing;
  cout << "Enter amount for miscellaneous ";
  cin >> actual.miscellaneous;

//Calculate the student's expenditures for the month
actual.gross =(actual.housing + actual.utilities + actual.householdExpenses + actual.transporation + actual.food + actual.medical + actual.insurance + actual.entertainment + actual.clothing + actual.miscellaneous);

//To see if you are under budget
if (actual.gross < EXP_AMT)
{
actual.under = EXP_AMT - actual.gross;
cout << "You are below your monthly budget so you saved $ " << actual.under << endl;
}

//To see if you are right at your budget
if (EXP_AMT == actual.gross)
{
cout << "You are right at your monthly budget";
}

//To see if you are over the budget
if (EXP_AMT < actual.gross)
{
actual.over = actual.gross - EXP_AMT;
cout << "You are over your monthly budget by: $ " << actual.over <<endl;
}
{
	ofstream file_("budget.txt");
	if(file_.is_open () ){
		//print to show how much you saved
if (actual.gross < EXP_AMT)
{
actual.under = EXP_AMT - actual.gross;
file_<< "You are below your monthly budget so you saved $ " << actual.under << endl;
}

//print if you are at the budget
if (EXP_AMT == actual.gross)
file_<< "You are right at your monthly budget";
}

//print if you are over budget
if (EXP_AMT < actual.gross)
{
actual.over = actual.gross - EXP_AMT;
file_<< "You are over your monthly budget by: $ " << actual.over <<endl;
		file_.close();
}
		std::cin.get ();
		while (actual.gross <=1500);
		system ("pause");
		return 0;
		
}
I am also having trouble understanding the two errors.

Perhaps if you told us the errors, they would be easier to understand.

I will say that a do-while loop looks like this:

1
2
3
4
do 
{
  // things to do
} while (some condition);


and yours looks nothing like that.
Last edited on
The error is intelliSense: expected a } at line 104 and
error C1075: end of file before the left brace '{' at line 105
The error is that your do-while loop is a mess and just plain wrong.

The while isn't connected to the do block. It's meant to be. Your left and right braces are a mess. Use indentation so you can see what you're doing.
Last edited on
Topic archived. No new replies allowed.