Don't leave us! Keep pestering us with more questions! :D
That's what we live for, that's what we sit before the computer for, that's where we get all our posts from! :p
Alright, good luck.
Printable View
Don't leave us! Keep pestering us with more questions! :D
That's what we live for, that's what we sit before the computer for, that's where we get all our posts from! :p
Alright, good luck.
Did you put the entire if block into the while loop? Is that what you really want to do?
Thanks for that Elysia.. I am happy to hear that. I will ofcourse keep send you questions. I really appreciate it. Dont worry :P
I have been sitting with a problem for 20 hours myself searching on the internet and thinking about a solution but cant solve this. I beleive that what I want to do is a bit special, perheps there are functions/syntax to help this problem out.
Actually it is 2 things/questions that is happening at the same time.
But I will start out with the first question to see if the first thing could be solved to not make it to difficult.
.................................................. .................................................. ..........................................
Here we go :)
What I want to do now as I can scan a file and find the lowest value for example "Low" for the entire file. As the example below with 4 lines that contains 2 different dates. I want to store the Lowest Value of Low for each date into a variable. The two variables I have named: "IntraLow9" and "IntraLow8".
01/12/2006,2005,16.19,16.20,16.19,16.19,2100,16.19
01/12/2006,2006,16.20,16.20,16.20,16.20,200,16.20
01/13/2006,2005,16.20,16.20,16.18,16.20,1700,16.18
01/13/2006,2006,16.18,16.19,16.12,16.19,1500,16.19
As the code is scanning the file from the top to bottom I have managed to do a code that do a count when a new date occurs.(´Perheps´ this will be of help for the solution)
The variable is called: "DateCount" and counts down from 11. This meen when the first date happens in the file it will have a count of 9 and for the other date 8.
So the first key for the first date is 9 then. What I want to do now is to store the lowest value of Low into the variable called: IntraLow9
I know that my approach: (IntraLow + DateCount) is wrong but perheps you understand what I am ´trying´ to do. (It is kind of "Intelligent" assignment to variables)
How could it be possible to do something like this ? (Hope you can understand my explanation of the problem :) )
Code:#include "stdafx.h"
#include <iostream>
#include <fstream>
#include <sstream>
#include <string>
using namespace std;
int main ()
{
std::string Date;
std::string DateDummy;
double DateCount = 11;
double IntraLow9 = 1000;
double IntraLow8 = 1000;
char Comma;
int Time = 0;
double Open = 0;
double High = 0;
double Low = 0;
double Close = 0;
int Volume = 0;
double IntraHigh = 0;
double IntraLow = 1000;
double IntraVolume = 0;
ofstream Test;
Test.open ("file2.txt");
ifstream myfile ("CCE.txt");
ifstream file0 ("file0.txt");
while ( getline(myfile, Date, ',') )
{
myfile >> Time; // 2111
myfile >> Comma;
myfile >> Open; // 35.23
myfile >> Comma;
myfile >> High; // 35.23
myfile >> Comma;
myfile >> Low; // 35.20
myfile >> Comma;
myfile >> Close; // 35.22
myfile >> Comma;
myfile >> Volume; // 15600
myfile >> Comma;
myfile >> Close; // 35.22
myfile.get(); // read in trailing newline character
if ((Low < (IntraLow + DateCount)) && (DateCount != 11) && (Date == DateDummy)) // I am trying to make the code understand
{ // that (IntraLow + DateCount) meens: IntraLow9 where DateCount
(IntraLow + DateCount) = Low; // for the moment is 9 and then put the lowest value for the
} // date into double IntraLow9.
//////////////////////////////////////////////////////////////////////
if (Date != DateDummy)
{
DateDummy = Date;
DateCount = (DateCount - 1); // DateCount has a CountDown for the Dates ´while´ the code is running. Starting at 11
}
//////////////////////////////////////////////////////////////////////
} // End of While Statement
Test << IntraLow9 <<"\n";
return 0;
} // int main braces
You probably need to learn arrays for this. I would actually use a map and map the date string to the current low value. If the times will always be greater than 0 then this is really easy once you learn how to use the map.
I'd also consider starting a new thread, since this one will be hard to follow for anybody who hasn't been doing so already.
The quick'n'dirty way to do this would be arrays, I would think. Use IntraLow[DateCount] instead.
I'm sure the STL has many forms of associative arrays, and someone who actually knows the STL will be along to tell you; ten seconds of Google says that std::map might be something to look at.
I'm not sure I understand your problem. Perhaps I simply need to re-read it, but even so, this is something I want to comment on. This is bad what you're doing.
You're actually putting the { in a indentation LESS than the if. { and } should always be on the same level as your block element, such as if, while, etc.
So indent those { and }, along with all the code inside.
Should look like this:
Code:
if ((Low < (IntraLow + DateCount)) && (DateCount != 11) && (Date == DateDummy)) // I am trying to make the code understand
{ // that (IntraLow + DateCount) meens: IntraLow9 where DateCount
(IntraLow + DateCount) = Low; // for the moment is 9 and then put the lowest value for the
} // date into double IntraLow9.
if (Date != DateDummy)
{
DateDummy = Date;
DateCount = (DateCount - 1); // DateCount has a CountDown for the Dates ´while´ the code is running. Starting at 11
}
} // End of While Statement
Thanks.. I will read about arrays and maps through internet and also start a new thread later on...
Coding
There are excellent tutorials for that on this site. I think.
Anyway, check them out and see if they help.
std::vector and std::map are those you might want to take a look at.
Ok, thanks Elysia, I will take a look at them too..