C++ prog won't write to xml properly

Will someone please give me some insight as to why I'm not getting the right output to the xml file please? Thank you. I'm a C++ n00b so don't beat me up too bad. atleast my first post has the code between code tags. ;)
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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
#include <iostream>
#include <string>
#include <fstream>
#include <iomanip>

using namespace std;

class Revenue
{
private:
	string divName;            //division name
	string divNum;               //divsion number
	int numEmp;              //number of employees
	double ttlSales;        //total sales
	double ttlCosts;       //total costs
	double profit;         //profit
	double costPerEmp;      //cost per employee
	
public:

	static int numDivs;      //number of divisions    this one is static,
	static int quarterNum;    // quarter number            this one also.

	Revenue();                //Defualt constructor


	string setdivName();
	string getdivName()
	{ return divName; }

	string setdivNum();
	string getdivNum()
	{ return divNum; }

	int setnumEmp();
	int getnumEmp()
	{return numEmp; }

	double setttlSales();
	double getttlSales()
	{ return ttlSales; }

	double setttlCosts();
	double getttlCosts()
	{ return ttlCosts; }

	double setprofit(double ttlSales, double ttlCosts);
	double getprofit()
	{ return profit; }

	double setcostPerEmp(double ttlCosts, double numEmp);
	double getcostPerEmp()
	{ return costPerEmp; }

	static int setnumDivs();
	static int getnumDivs()
	{ return numDivs; }

	static int setquarterNum();
	static int getquarterNum()
	 { return quarterNum; }
};

/******Defualt Constructor*********/

Revenue::Revenue()
{
	ttlSales = ttlCosts = profit = costPerEmp = 0;  divNum = numEmp = 0;
}

/***********Revenue::setdivName***************/

string Revenue::setdivName()
{
	cout << "Type the division name.\n";
	cin.ignore(100, '\n');
	getline(cin, divName);
	return ("string");
}

/***********Revenue::setdivNum****************/

string Revenue::setdivNum()
{
	cout << "Enter the division number.\n";
	cin >> divNum;
	if(divNum.length() != 4)
	{
	do
	{
		cout << "The division number can only be 4 digits in length. Try again: \n";
	     cin >> divNum;
	}

	while(divNum.length() != 4);
	}

	return (divNum);
}

/**************Revenue::setnumEmp**************/

int Revenue::setnumEmp()
{
	cout << "Enter the number of employees.\n";
	cin >> numEmp;
	return (numEmp);
}

/************Revenue::setttlSales*************/

double Revenue::setttlSales()
{
	cout << "Input the total sales amount.\n";
	cin >> ttlSales;
	return (ttlSales);
}

/*************Revenue::setttlCosts************/

double Revenue::setttlCosts()
{
	cout << "Input the total Costs amount.\n";
	cin >> ttlCosts;
	return (ttlCosts);
}

/************Revenue::setprofit********/

double Revenue::setprofit(double ttlSales, double ttlCosts)
{ 
	profit = ttlSales - ttlCosts;
	return (profit);
}

/*************Revenue::setcostPerEmp*********/

double Revenue::setcostPerEmp(double ttlCosts, double NumEmp)
{
     costPerEmp = ttlCosts/numEmp;
	 return (costPerEmp);
}

/**********Revenue::setnumDivs**************/

int Revenue::setnumDivs()
{
	cout << "How many Revenue records will you be inputing this session?\n";
	cin >> Revenue::numDivs;
	return (numDivs);
}

/**********Revenue::setquarterNum***********/

int Revenue::setquarterNum()
{
	cout << "The information inputed into this program is for which quarter?." << endl;
	cin >> quarterNum;
	return (quarterNum);
	
}

/***************Initialize static variables*****************************/
int Revenue::numDivs = 0;
 

int Revenue::quarterNum = 0;


int desIntro();

int choice;

int main()
{
	int num = 0;

	
	Revenue ReV;

    desIntro();
		do
	    {
		if(choice == 2)
			{cout << "The program will now exit.\n";
		     return (0);
		    }
        else if(choice == 1)
	           {break;}
        else if(choice != 1 || choice != 2)
               { cout << " you did not enter a '1' or a '2', try again: \n";
                 cin >> choice;
	           }
		}
		  while(choice != 1 || choice != 2);


	 ReV.setnumDivs();
	 do
	 {

    ReV.setquarterNum();

	ReV.setdivName();

	ReV.setdivNum();

	ReV.setnumEmp();

    ReV.setttlSales();

	ReV.setttlCosts();

	ReV.setprofit(ReV.getttlSales(), ReV.getttlCosts());

    ReV.setcostPerEmp(ReV.getttlCosts(), ReV.getttlSales());

	cout << showpoint << fixed << setprecision(2);
	
	cout << "Division Name: " << ReV.getdivName() << endl;

	cout << "Division Number: " << ReV.getdivNum() << endl;

	cout << "Quarter: " << ReV.getquarterNum() << endl;

	cout << "Number of employees: " << ReV.getnumEmp() << endl;

	cout << "Total Sales: " << ReV.getttlSales() << endl;

	cout << "Cost per employee: " << ReV.getcostPerEmp() << endl;

	cout << "Total Costs: " << ReV.getttlCosts() << endl;

	cout << "Profit per quarter: " << ReV.getprofit() << endl;


    Revenue* ReVA = new Revenue[Revenue::numDivs];          //intialize the dynamic array...yay..
	
		ReVA[num].setdivName();
	    ReVA[num].setdivNum();
	    ReVA[num].setnumEmp();
	    ReVA[num].getttlSales();
	    ReVA[num].getttlCosts();
	    ReVA[num].getprofit();
	    ReVA[num].getcostPerEmp();
	    num++;

		ofstream dMover;
     dMover.setf(ios_base::fixed, ios_base::floatfield);
     dMover.precision(2);
     dMover.open("cop2224_proj2.xml", ios::out | ios::app);
     dMover << "<?xml version='1.0' encoding='utf-8'?>\n";
     dMover << "<revenue>\n";
            for(int counter = 0; counter < num; counter++)
	            {
		     dMover << "   <Division>\n";
		     dMover << "          <DivisionName>" << ReVA[counter].getdivName() << "</DivisionName>\n";
		     dMover << "          <DivisionNumber>" << ReVA[counter].getdivNum() << "</DivisionNumber>\n";
		     dMover << "          <NumberofEmployees>" << ReVA[counter].getnumEmp() << "</NumberofEmployees>\n";
		     dMover << "          <TotalSales>" << ReVA[counter].getttlSales() << "</TotalSales>\n";
		     dMover << "          <TotalCosts>" << ReVA[counter].getttlCosts() << "</TotalCosts>\n";
		     dMover << "          <Profit>" << ReVA[counter].getprofit() << "</profit>\n";
		     dMover << "          <CostPerEmployee>" << ReVA[counter].getcostPerEmp() << "<CostPerEmployee>\n";
		     dMover << "   <Division>\n";
		     dMover << "   <Quarter>" << Revenue::quarterNum << "</Quarter>\n";
	         }

     dMover << "</revenue>\n";
     dMover.close();
	
	    cout << "===========================================================================\n";
	    cout << "Division record: " << num << " of " << Revenue::numDivs << " is complete.\n";
	    cout << "If you would you like to continue press '1' then the 'Enter' key. \n";
	    cout << "If you would like to quit, press '2' then the 'Enter' key.\n";
	    cin >> choice;

	    do
	        {
		    if(choice == 2)
			    {
				    cout << "The program will now exit.\n";
		         return (0);
		        }
              else if(choice == 1)
	               {
				       break;
		           }
	          else if(choice != 1 || choice != 2)
                   { 
				       cout << " you did not enter a '1' or '2', try again: \n";
                     cin >> choice;
	               }
		    }
		      while(choice != 1 || choice != 2);
	     }
            while(num != Revenue::numDivs);
			
	
	  
 cout << "The records have been written to cop2224_proj2.xml\n";
 cout << "The program will now shut down.\n";
 

 

	 return 0;
}


/***************description and introduction function****************/

int desIntro()
{
	cout <<  "The purpose of this program is to calculate corporate revenue\n";
	cout <<  "for a quarter of a business year.\n";
	cout <<  "The program will store a set of Revenue objects in a dynamic\n";
	cout <<  "array and output the values of each object to an XML file.\n";
	cout << endl;
    cout <<  "If you would like to continue press '1', then the 'Enter' key.\n";
    cout <<  "If you would like to exit the program press '2', then the 'Enter' key\n";
     cin >> choice;

		  return(0);
}
What do you mean by "the right output"? What output are you expecting to get? What output are you actually getting?
Line #262 - you need an upper case 'P' for the closing </Profit> tag.
Line #263 - you need to output "</CostPerEmployee>" i.e. a closing CostPerEmployee tag
Line #264 - you need to output "</Division>" i.e. a closing Division tag

That should do it
@MikeyBoy: When i run the program to the end, the xml file should be created, which it does that. However, the xml file is blank when I view it. if I use an xml editor, the info shows up in it but again not when I view the xml file normaly like in a webbrowser. if you run the code you'll see what I mean.

@ajh32: Thank you for finding those errors. I corrected them but unfortunatly I'm experiencing the same problem as before.
I also want to say that I'm unsure if the dynamic array is working correctly because the tags show in the xml editor but not the content of the array which is the idea behind sending the info to the xml in the first place.
Well, it might help if you actually posted the XML it's outputting. It would be easier to find the solution if you weren't making us guess what the problem is.
I'm at wits end here and have been guessing at this all day.


There is nothing to post as far as the xml because it is BLANK( I said that previously)

Now, if I use notepad to look at the xml file, it shows the tags but either no values are in between or there are zeros.

if you want me to post a blank file I will.

Here is updated code typo errors fixed:

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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
#include <iostream>
#include <string>
#include <fstream>
#include <iomanip>

using namespace std;

class Revenue
{
private:
	string divName;            //division name
	string divNum;               //divsion number
	int numEmp;              //number of employees
	double ttlSales;        //total sales
	double ttlCosts;       //total costs
	double profit;         //profit
	double costPerEmp;      //cost per employee
	
public:

	static int numDivs;      //number of divisions    this one is static,
	static int quarterNum;    // quarter number            this one also.

	Revenue();                //Defualt constructor


	string setdivName();
	string getdivName()
	{ return divName; }

	string setdivNum();
	string getdivNum()
	{ return divNum; }

	int setnumEmp();
	int getnumEmp()
	{return numEmp; }

	double setttlSales();
	double getttlSales()
	{ return ttlSales; }

	double setttlCosts();
	double getttlCosts()
	{ return ttlCosts; }

	double setprofit(double ttlSales, double ttlCosts);
	double getprofit()
	{ return profit; }

	double setcostPerEmp(double ttlCosts, double numEmp);
	double getcostPerEmp()
	{ return costPerEmp; }

	static int setnumDivs();
	static int getnumDivs()
	{ return numDivs; }

	static int setquarterNum();
	static int getquarterNum()
	 { return quarterNum; }
};

/******Defualt Constructor*********/

Revenue::Revenue()
{
	ttlSales = ttlCosts = profit = costPerEmp = 0;  divNum = numEmp = 0;
}

/***********Revenue::setdivName***************/

string Revenue::setdivName()
{
	cout << "Type the division name.\n";
	cin.ignore(100, '\n');
	getline(cin, divName);
	return (divName);
}

/***********Revenue::setdivNum****************/

string Revenue::setdivNum()
{
	cout << "Enter the division number.\n";
	cin >> divNum;
	if(divNum.length() != 4)
	{
	do
	{
		cout << "The division number can only be 4 digits in length. Try again: \n";
	     cin >> divNum;
	}

	while(divNum.length() != 4);
	}

	return (divNum);
}

/**************Revenue::setnumEmp**************/

int Revenue::setnumEmp()
{
	cout << "Enter the number of employees.\n";
	cin >> numEmp;
	return (numEmp);
}

/************Revenue::setttlSales*************/

double Revenue::setttlSales()
{
	cout << "Input the total sales amount.\n";
	cin >> ttlSales;
	return (ttlSales);
}

/*************Revenue::setttlCosts************/

double Revenue::setttlCosts()
{
	cout << "Input the total Costs amount.\n";
	cin >> ttlCosts;
	return (ttlCosts);
}

/************Revenue::setprofit********/

double Revenue::setprofit(double ttlSales, double ttlCosts)
{ 
	profit = ttlSales - ttlCosts;
	return (profit);
}

/*************Revenue::setcostPerEmp*********/

double Revenue::setcostPerEmp(double ttlCosts, double NumEmp)
{
     costPerEmp = ttlCosts/numEmp;
	 return (costPerEmp);
}

/**********Revenue::setnumDivs**************/

int Revenue::setnumDivs()
{
	cout << "How many Revenue records will you be inputing this session?\n";
	cin >> Revenue::numDivs;
	return (numDivs);
}

/**********Revenue::setquarterNum***********/

int Revenue::setquarterNum()
{
	cout << "The information inputed into this program is for which quarter?." << endl;
	cin >> quarterNum;
	return (quarterNum);
	
}

/***************Initialize static variables*****************************/
int Revenue::numDivs = 0;
 

int Revenue::quarterNum = 0;


int desIntro();

int choice;

int main()
{
	int num = 0;

	
	Revenue ReV;

    desIntro();
		do
	    {
		if(choice == 2)
			{cout << "The program will now exit.\n";
		     return (0);
		    }
        else if(choice == 1)
	           {break;}
        else if(choice != 1 || choice != 2)
               { cout << " you did not enter a '1' or a '2', try again: \n";
                 cin >> choice;
	           }
		}
		  while(choice != 1 || choice != 2);


	 ReV.setnumDivs();
	 do
	 {

    ReV.setquarterNum();

	ReV.setdivName();

	ReV.setdivNum();

	ReV.setnumEmp();

    ReV.setttlSales();

	ReV.setttlCosts();

	ReV.setprofit(ReV.getttlSales(), ReV.getttlCosts());

    ReV.setcostPerEmp(ReV.getttlCosts(), ReV.getttlSales());

	cout << showpoint << fixed << setprecision(2);
	
	cout << "Division Name: " << ReV.getdivName() << endl;

	cout << "Division Number: " << ReV.getdivNum() << endl;

	cout << "Quarter: " << ReV.getquarterNum() << endl;

	cout << "Number of employees: " << ReV.getnumEmp() << endl;

	cout << "Total Sales: " << ReV.getttlSales() << endl;

	cout << "Cost per employee: " << ReV.getcostPerEmp() << endl;

	cout << "Total Costs: " << ReV.getttlCosts() << endl;

	cout << "Profit per quarter: " << ReV.getprofit() << endl;


    Revenue* ReVA = new Revenue[Revenue::numDivs];          //intialize the dynamic array...yay..
	
		ReVA[num].getdivName();
	    ReVA[num].getdivNum();
	    ReVA[num].getnumEmp();
	    ReVA[num].getttlSales();
	    ReVA[num].getttlCosts();
	    ReVA[num].getprofit();
	    ReVA[num].getcostPerEmp();
	    num++;

		ofstream dMover;
     dMover.setf(ios_base::fixed, ios_base::floatfield);
     dMover.precision(2);
     dMover.open("cop2224_proj2.xml", ios::out | ios::app);
     dMover << "<?xml version='1.0' encoding='utf-8'?>\n";
     dMover << "<revenue>\n";
            for(int counter = 0; counter < num; counter++)
	            {
		     dMover << "   <Division>\n";
		     dMover << "          <DivisionName>" << ReVA[counter].getdivName() << "</DivisionName>\n";
		     dMover << "          <DivisionNumber>" << ReVA[counter].getdivNum() << "</DivisionNumber>\n";
		     dMover << "          <NumberofEmployees>" << ReVA[counter].getnumEmp() << "</NumberofEmployees>\n";
		     dMover << "          <TotalSales>" << ReVA[counter].getttlSales() << "</TotalSales>\n";
		     dMover << "          <TotalCosts>" << ReVA[counter].getttlCosts() << "</TotalCosts>\n";
		     dMover << "          <Profit>" << ReVA[counter].getprofit() << "</Profit>\n";
		     dMover << "          <CostPerEmployee>" << ReVA[counter].getcostPerEmp() << "</CostPerEmployee>\n";
		     dMover << "   </Division>\n";
		     dMover << "   <Quarter>" << Revenue::quarterNum << "</Quarter>\n";
	         }

     dMover << "</revenue>\n";
     dMover.close();
	
	    cout << "===========================================================================\n";
	    cout << "Division record: " << num << " of " << Revenue::numDivs << " is complete.\n";
	    cout << "If you would you like to continue press '1' then the 'Enter' key. \n";
	    cout << "If you would like to quit, press '2' then the 'Enter' key.\n";
	    cin >> choice;

	    do
	        {
		    if(choice == 2)
			    {
				    cout << "The program will now exit.\n";
		         return (0);
		        }
              else if(choice == 1)
	               {
				       break;
		           }
	          else if(choice != 1 || choice != 2)
                   { 
				       cout << " you did not enter a '1' or '2', try again: \n";
                     cin >> choice;
	               }
		    }
		      while(choice != 1 || choice != 2);
	     }
            while(num != Revenue::numDivs);
			
	
	  
 cout << "The records have been written to cop2224_proj2.xml\n";
 cout << "The program will now shut down.\n";
 

 

	 return 0;
}


/***************description and introduction function****************/

int desIntro()
{
	cout <<  "The purpose of this program is to calculate corporate revenue\n";
	cout <<  "for a quarter of a business year.\n";
	cout <<  "The program will store a set of Revenue objects in a dynamic\n";
	cout <<  "array and output the values of each object to an XML file.\n";
	cout << endl;
    cout <<  "If you would like to continue press '1', then the 'Enter' key.\n";
    cout <<  "If you would like to exit the program press '2', then the 'Enter' key\n";
     cin >> choice;

		  return(0);
}
Sorry... is the XML file empty, or does it contain anything? You're saying contradictory things.
after the program is run and I check the xml file. I doubleclick it and it is brought up in Internet Explorer. At that time it is blank, nothing but a white back ground.

Now, if I click file and go to edit xml file, the file is then brought up in notpad. Once in notepad you can see the tags that are suppossed to show up when you view the file in the web browser. In place of the values that are suppossed to be there are either a space or zeros. but like I said, the tags are there.

Here is the output from using notepad to open the xml file:

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

<?xml version='1.0' encoding='utf-8'?>
<revenue>
   <Division>
          <DivisionName></DivisionName>
          <DivisionNumber> </DivisionNumber>
          <NumberofEmployees>0</NumberofEmployees>
          <TotalSales>0.00</TotalSales>
          <TotalCosts>0.00</TotalCosts>
          <Profit>0.00</Profit>
          <CostPerEmployee>0.00</CostPerEmployee>
   </Division>
   <Quarter>2</Quarter>
</revenue>
<?xml version='1.0' encoding='utf-8'?>
<revenue>
   <Division>
          <DivisionName></DivisionName>
          <DivisionNumber> </DivisionNumber>
          <NumberofEmployees>0</NumberofEmployees>
          <TotalSales>0.00</TotalSales>
          <TotalCosts>0.00</TotalCosts>
          <Profit>0.00</Profit>
          <CostPerEmployee>0.00</CostPerEmployee>
   </Division>
   <Quarter>1</Quarter>
   <Division>
          <DivisionName></DivisionName>
          <DivisionNumber> </DivisionNumber>
          <NumberofEmployees>0</NumberofEmployees>
          <TotalSales>0.00</TotalSales>
          <TotalCosts>0.00</TotalCosts>
          <Profit>0.00</Profit>
          <CostPerEmployee>0.00</CostPerEmployee>
   </Division>
   <Quarter>1</Quarter>
</revenue>




Again, if I view this file in a web browser, nothing shows.

Last edited on
You can only have one top level tag (in your case <revenue>)

Which is what IE tells me!

Only one top level element is allowed in an XML document.
Error processing resource 'file:///C:/Documents and Settings/Andy...

<revenue>
-^

If you need more than one <revenue> entry in a single XML file, then they'll need to go inside another tag.

And I can see two XML declarations

<?xml version='1.0' encoding='utf-8'?>

This should turn up just once, as the very first line of the file.

The top part of your data works fine for me!

<?xml version='1.0' encoding='utf-8'?>
<revenue>
<Division>
<DivisionName></DivisionName>
<DivisionNumber> </DivisionNumber>
<NumberofEmployees>0</NumberofEmployees>
<TotalSales>0.00</TotalSales>
<TotalCosts>0.00</TotalCosts>
<Profit>0.00</Profit>
<CostPerEmployee>0.00</CostPerEmployee>
</Division>
<Quarter>2</Quarter>
</revenue>

:-)

as does

<?xml version='1.0' encoding='utf-8'?>
<TaxationData>
<Revenue>
<Division>
<DivisionName></DivisionName>
<DivisionNumber> </DivisionNumber>
<NumberofEmployees>0</NumberofEmployees>
<TotalSales>0.00</TotalSales>
<TotalCosts>0.00</TotalCosts>
<Profit>0.00</Profit>
<CostPerEmployee>0.00</CostPerEmployee>
</Division>
<Quarter>2</Quarter>
</Revenue>
<?xml version='1.0' encoding='utf-8'?>
<Revenue>
<Division>
<DivisionName></DivisionName>
<DivisionNumber> </DivisionNumber>
<NumberofEmployees>0</NumberofEmployees>
<TotalSales>0.00</TotalSales>
<TotalCosts>0.00</TotalCosts>
<Profit>0.00</Profit>
<CostPerEmployee>0.00</CostPerEmployee>
</Division>
<Quarter>1</Quarter>
<Division>
<DivisionName></DivisionName>
<DivisionNumber> </DivisionNumber>
<NumberofEmployees>0</NumberofEmployees>
<TotalSales>0.00</TotalSales>
<TotalCosts>0.00</TotalCosts>
<Profit>0.00</Profit>
<CostPerEmployee>0.00</CostPerEmployee>
</Division>
<Quarter>1</Quarter>
</Revenue>
</TaxationData>

(where I tweaked Revenue so it aligned with the capitialization convention)

Andy



Last edited on
ok now this is wierd ...if I put an (&) infront of the array on lines 257 and 258. the xml file executes properly but I still don't get the correct info. Now the first 2 tags have the memory address to what I need instead of the value. After taking the (&) away and running the program again i get the same results as before i put them in so it definetly is the (&) making the file output correctly. What I mean by that is, in IE now the xml file shows it's tags and what is suppossed to be the correct values but they are strill incorrect. here is what is shown to me on the screen:
1
2
3
4
5
6
7
8
9
10
11
<?xml version="1.0" encoding="UTF-8"?>
-<revenue> 
-<Division> 
    <DivisionName>0040F9C0</DivisionName>
           <DivisionNumber>0040F9E8</DivisionNumber> 
           <NumberofEmployees>0</NumberofEmployees>
           <TotalSales>0.00</TotalSales> 
           <TotalCosts>0.00</TotalCosts> 
           <Profit>0.00</Profit> 
           <CostPerEmployee>0.00</CostPerEmployee> </Division>    <Quarter>1</Quarter> 
</revenue>
@Andy: Thanks for checking it out. Unfortunatly i have no idea what the capitalization convention is. it's already down to the wire and I have to turn the project in soon. I wish i would have swallowed my pride a little sooner and hit up the forum earlier than today.

THe most frustrating part of this assignment is that the prof told us we had to write this crap into an xml and never showed us how or gave us any literature on it or even lectured about it in class...nor is it in out text book...just to do it....it's been nothing but confusion, frustration and headaches. glad this is the last assignment..

If you are able to break down your explanation, I would really like to understand whats going on but with the way you already have, I'm lost.
After you've set the contents of ReV, you output all the contents of it to cout. Are the values all what you expect?

Can you do the same for ReVA, and check whether that also holds the values you expect?
Or you could use an XML library like libxml2:

http://www.xmlsoft.org/

There are plenty of code examples to show you how to use it to create well formed XML documents.
ok, got it completly figured out. A guy in my class took it upon himself to help correct it for me. It turns out. part of the code to send the data to the xml was incorrect. Also, I had it to where the file was being closed everytime the code moved through the loop. Also, the array ReVA isn't even being initialized with any data into it's elements. the array also needed tobe moved above the main do/while, another reason why the data wouldn't show up when i called the elements of the array into the xml file. I also put the 'while' statment on the wrong line. I took out the cout statements because i was really using them to validate the arithmetic. here is the updated code. It works exactly per the parameters given by the professor. i Just want to say 'Thanks!' to you guys for taking an interest in my programing shenanigins. Here is the updated code
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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295

#include <iostream>
#include <string>
#include <fstream>
#include <iomanip>

using namespace std;

class Revenue
{
private:
	string divName;            //division name
	string divNum;               //divsion number
	int numEmp;              //number of employees
	double ttlSales;        //total sales
	double ttlCosts;       //total costs
	double profit;         //profit
	double costPerEmp;      //cost per employee
	
public:

	static int numDivs;      //number of divisions    this one is static,
	static int quarterNum;    // quarter number            this one also.

	Revenue();                //Defualt constructor


	string setdivName();
	string getdivName()
	{ return divName; }

	string setdivNum();
	string getdivNum()
	{ return divNum; }

	int setnumEmp();
	int getnumEmp()
	{return numEmp; }

	double setttlSales();
	double getttlSales()
	{ return ttlSales; }

	double setttlCosts();
	double getttlCosts()
	{ return ttlCosts; }

	double setprofit(double ttlSales, double ttlCosts);
	double getprofit()
	{ return profit; }

	double setcostPerEmp(double ttlCosts, double numEmp);
	double getcostPerEmp()
	{ return costPerEmp; }

	static int setnumDivs();
	static int getnumDivs()
	{ return numDivs; }

	static int setquarterNum();
	static int getquarterNum()
	 { return quarterNum; }
};

/******Defualt Constructor*********/

Revenue::Revenue()
{
	ttlSales = ttlCosts = profit = costPerEmp = 0;  divNum = numEmp = 0;
}

/***********Revenue::setdivName***************/

string Revenue::setdivName()
{
	cout << "Type the division name.\n";
	cin.ignore(100, '\n');
	getline(cin, divName);
	return (divName);
}

/***********Revenue::setdivNum****************/

string Revenue::setdivNum()
{
	cout << "Enter the division number.\n";
	cin >> divNum;
	if(divNum.length() != 4)
	{
	do
	{
		cout << "The division number can only be 4 digits in length. Try again: \n";
	     cin >> divNum;
	}

	while(divNum.length() != 4);
	}

	return (divNum);
}

/**************Revenue::setnumEmp**************/

int Revenue::setnumEmp()
{
	cout << "Enter the number of employees.\n";
	cin >> numEmp;
	return (numEmp);
}

/************Revenue::setttlSales*************/

double Revenue::setttlSales()
{
	cout << "Input the total sales amount.\n";
	cin >> ttlSales;
	return (ttlSales);
}

/*************Revenue::setttlCosts************/

double Revenue::setttlCosts()
{
	cout << "Input the total Costs amount.\n";
	cin >> ttlCosts;
	return (ttlCosts);
}

/************Revenue::setprofit********/

double Revenue::setprofit(double ttlSales, double ttlCosts)
{ 
	profit = ttlSales - ttlCosts;
	return (profit);
}

/*************Revenue::setcostPerEmp*********/

double Revenue::setcostPerEmp(double ttlCosts, double NumEmp)
{
     costPerEmp = ttlCosts/numEmp;
	 return (costPerEmp);
}

/**********Revenue::setnumDivs**************/

int Revenue::setnumDivs()
{
	cout << "How many Revenue records will you be inputing this session?\n";
	cin >> Revenue::numDivs;
	return (numDivs);
}

/**********Revenue::setquarterNum***********/

int Revenue::setquarterNum()
{
	cout << "The information inputed into this program is for which quarter?." << endl;
	cin >> quarterNum;
	return (quarterNum);
	
}

/***************Initialize static variables*****************************/
int Revenue::numDivs = 0;
 

int Revenue::quarterNum = 0;


int desIntro();

int choice;

int main()
{
	int num = 0;

	
	Revenue ReV;
	ofstream dMover;

    desIntro();
		do
	    {
		if(choice == 2)
			{cout << "The program will now exit.\n";
		     return (0);
		    }
        else if(choice == 1)
	           {break;}
        else if(choice != 1 || choice != 2)
               { cout << " you did not enter a '1' or a '2', try again: \n";
                 cin >> choice;
	           }
		}
		  while(choice != 1 || choice != 2);


	 ReV.setnumDivs();
	 ReV.setquarterNum();

	 Revenue* ReVA = new Revenue[Revenue::numDivs];          //intialize the dynamic array...yay..
	 dMover.open("cop2224_proj2.xml", ios::out);
	 dMover << "<revenue>" << endl;
	 do
	 {
		 ReVA[num].setdivName();
	
		 ReVA[num].setdivNum();
	
		 ReVA[num].setnumEmp();
	
		 ReVA[num].setttlSales();
	
		 ReVA[num].setttlCosts();

		 ReVA[num].setprofit(ReVA[num].getttlSales(), ReVA[num].getttlCosts());

		 ReVA[num].setcostPerEmp(ReVA[num].getttlCosts(), ReVA[num].getnumEmp());

     dMover.setf(ios_base::fixed, ios_base::floatfield);
     dMover.precision(2);
     
		     dMover << "\t<Division>\n";
		     dMover << "\t\t<DivisionName>" << ReVA[num].getdivName() << "</DivisionName>" << endl;
		     dMover << "\t\t<DivisionNumber>" << ReVA[num].getdivNum() << "</DivisionNumber>" << endl;
		     dMover << "\t\t<NumberofEmployees>" << ReVA[num].getnumEmp() << "</NumberofEmployees>" << endl;
		     dMover << "\t\t<TotalSales>" << ReVA[num].getttlSales() << "</TotalSales>" << endl;
		     dMover << "\t\t<TotalCosts>" << ReVA[num].getttlCosts() << "</TotalCosts>" << endl;
		     dMover << "\t\t<Profit>" << ReVA[num].getprofit() << "</Profit>" << endl;
		     dMover << "\t\t<CostPerEmployee>" << ReVA[num].getcostPerEmp() << "</CostPerEmployee>" << endl;
		     dMover << "\t</Division>" << endl;
	         //}   
			
		num++;

	    cout << "===========================================================================\n";
	    cout << "Division record: " << num << " of " << Revenue::numDivs << " is complete.\n";
	    cout << "If you would you like to continue press '1' then the 'Enter' key. \n";
	    cout << "If you would like to quit, press '2' then the 'Enter' key.\n";
	    cin >> choice;

	    do
	        {
		    if(choice == 2)
			    {
				    cout << "The program will now exit.\n";
						dMover << "\t<Quarter>" << Revenue::quarterNum << "</Quarter>" << endl;
						dMover << "</revenue>";
					dMover.close();
		         return (0);
		        }
              else if(choice == 1)
	               {
				       break;
		           }
	          else if(choice != 1 || choice != 2)
                   { 
				       cout << " you did not enter a '1' or '2', try again: \n";
                     cin >> choice;
	               }
		    }
		      while(choice != 1 || choice != 2);
	     }
            while(num != Revenue::numDivs);
			
		dMover << "\t<Quarter>" << Revenue::quarterNum << "</Quarter>" << endl;
		dMover << "</revenue>";
	  
 cout << "The records have been written to cop2224_proj2.xml\n";
 cout << "The program will now shut down.\n";
 
 dMover.close();
 

	 return 0;
}


/***************description and introduction function****************/

int desIntro()
{
	cout <<  "The purpose of this program is to calculate corporate revenue\n";
	cout <<  "for a quarter of a business year.\n";
	cout <<  "The program will store a set of Revenue objects in a dynamic\n";
	cout <<  "array and output the values of each object to an XML file.\n";
	cout << endl;
    cout <<  "If you would like to continue press '1', then the 'Enter' key.\n";
    cout <<  "If you would like to exit the program press '2', then the 'Enter' key\n";
     cin >> choice;

		  return(0);
}
Topic archived. No new replies allowed.