How can I transfer selected values from an inFile into an outFile?

Hi. My assignment asks me to read inputs from a certain file which has data as shown below:


Date            Time, Price,Volume, Value, Condition
07/05/2014 12:12:12 PM, 4.3, 2000, 450030, AB CD
07/05/2014 12:11:30 PM, 5.4, 32000, 65930, 
07/05/2014 12:09:32 PM, 4.3, 2899, 560030, CD
.
.
.
07/05/2014 10:50:04 AM 4.3, 8750, 123789, F


And my program should have 4 options:
1. Display date, highest price, and start time(s) (in 24 hour format) of that highest price.
2. Display date, lowest price, and start time(s) (in 24 hour format) of that highest price.
3. Create output file and put the inputs into it in this format:
date, time, price, volume, value
where time is the start time of that particular price, volume is the total volume of that price, and value is the total value for that price.
4. Exit the program.

My codes for options 1 & 2 works fine, but my option 3 produces a wrong result.
Meaning, for the above input, the output File should have something like this:
07/05/2014, 10:05:04, 4.3, 13649, 1583879
07/05/2014, 12:11:30, 5.4, 32000, 65930

But, my output is something like this:
07/05/2014 12:12:12 PM, 4.3, 2000, 450030
07/05/2014 12:09:32 PM, 4.3, 2899, 560030
07/05/2014 10:50:04 AM 4.3, 8750, 123789


The following is my code for option 3:
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
else if (menu == 3)
	{
		ofstream outFile("output.txt"); 

		Shares share1 = shareList.get(0);
		double price1 = share1.getTradePrice();
		time24 time1 = share1.getT();

		int sumVolume = share1.getVolume();
		double sumValue = share1.getValue();

		for (int i = 1; i < shareList.countLine(); i++)
		{
			Shares share2 = shareList.get(i); //inputing the first string of array and input into the object		
			double price2 = share2.getTradePrice();
			time24 time2 = share2.getT();

			if (price1 == price2)
			{
				for (int i = 0; i < shareList.countLine(); i++)
				{
					if (time2.getHour() <= time1.getHour()
						&& time2.getMinute() <= time1.getMinute()
						&& time2.getSecond() <= time1.getSecond())
					{
						time1 = time2;
					}
				}
			}
			else
			{
				outFile << share1.getD1() << ", "
					<< time1 << ", "
					<< price1 << ", "
					<< sumVolume << ", "
					<< sumValue << endl;
			}
			sumVolume = share2.getVolume();
			sumValue = share2.getValue();
			share1 = share2; 
		}
		outFile.close();
	}


I'm not sure where it went wrong.
Can someone tell me?
I didn't read your code, but from what you output is and is supposed to be, it looks like the only problem is that you aren't changing the time into a 24 hour format. Since you already did this for the first two problems, I'm really not sure why you're having trouble now.
Topic archived. No new replies allowed.