Need help with storing array values

Hi, please see below for my method code.
Every time the program runs, user enter bids for Work1 and the bids are passed into the function below and through the function, the highest bid is selected and displayed out.

But the problem is if user continue and enter bids for Work2 and the process goes round again. This time, Work2 highest bid will replace Work1 highest bid and display out. In my txt file, only Work2 highest bid is displayed.


What can I do so that both Work1 & Work2 highest bids are stored and displayed?
Please help, Thank you.

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
void WorkBid::writeFile(WorkBid bids[], int n)
{
	WorkBid highest;
	ofstream myFile("WorkBid.txt");

	int i;
	
	myFile << "The highest work bids for this season are: \n";

	highest = bids[0];
		for (i=0; i<n; i++)
		{	
	 			if (highest < bids[i])
			{
				highest = bids[i];
			}	
		}
		
		outFile<<"\nBid id : " << highest.bidid << endl;

		outFile<<"\nPrice quotes : $"<< highest.pricequote << endl;


	outFile.close(); 
}
Last edited on
I tried adding in ios::app. But now the program shows all the datas instead of only the highest datas

Is there anyway to solve it?
Of course there is. You obviously want on some calls to start from scratch and on others to append. The caller, who should know, must pass that info to the function.

You could pass the filename too, because now you will always write to same file and the only way for the user to change the name is to obtain the sources, edit, and recompile.
Topic archived. No new replies allowed.