Is it just me or are you COMPLETELY ignoring my suggestions about fixing your code mess?Code:if (condition) { code; }
Yes, you are right about that.. i forgot it... but still the function to find the "Highest Time Value" doesn´t work...
I do have compile success now but with the code above I have no output to the file: Test
Look at the code inside the if block. Should that code really be there?
Also, it's hard to find exact problems without the latest, complete code. Maybe you can fix up all your indentations and post the latest complete code so we can have a better picture of what is going on.
Elyisa, I am defenetively not ignoring your suggestions. Remember I am a quite of a beginner with this compared to you... my code doesnt look like a mess that you said.. but not perfect though...
But I am trying better and better... The tabs doesn´t really work out 100 % for me why the code could look a bit like that... but the important is that I am trying.. please have patience...
Last edited by Coding; 12-18-2007 at 04:13 PM.
Thanks Elysia...I will do that...trust me I am trying. Many things to think of in the begining
So, you should really un-indent your if-line to the same level as the while above it, as it's at the same level. And look at the code inside the if-statement - what does it actually do?
--
Mats
Compilers can produce warnings - make the compiler programmers happy: Use them!
Please don't PM me for help - and no, I don't do help over instant messengers.
This is my complete code (I hope this is more readable, good for me to know if it´s not. Thanks!)
I think the code inside the if statement (if (TIme > HighestTim) should be there as if it finds a higher value
of the time that is "saved" or by default in the variable: HighestTim. Then the current Time that is red will replace this value with this higher TimeValue ?
Code:#include "stdafx.h" #include <iostream> #include <fstream> #include <sstream> #include <string> using namespace std; int main () { std::string Date; int Time = 0; char Comma; double Open = 0; double High = 0; double Low = 0; double Close = 0; int Volume = 0; int HighestTim = 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 (Time > HighestTim) { HighestTim = Time; Test << "Test " << HighestTim <<"\n"; return 0; } } // int main braces
Last edited by Coding; 12-18-2007 at 04:36 PM.
Yep, much better!
You probably don't need to indent so much, though, because it will make your code zillioningly long when you have a lot of blocks! Just one tab or 4 spaces are usually enough.
You also missed indenting inside that while.
Otherwise it looks very good!
Thanks Elysia. I beleive you meen like that inside of the while. If it is... Then I should know now how it should be done
You are doing two different things inside your if block. One, you are checking to see if the Time is greater than the current highest value. Two, you are printing out the highest time that was found. But checking the current time to see if it is the highest is something that should be done while you are reading in the times, right? And printing out the highest should only be done at the end after all times have been read in, right?
That's the ticket! Now it looks very nice!
Now you just have to hunt down those bugs in the code
Also note that main should always return a value and so by putting it inside that if block, it will only return something if the condition is true. Not a good thing, is it? If that condition is false, then main won't return (an explicit) value. You should also get a warning (at least in C++) saying that not all control paths return a value. Move that return outside the if. I don't think you actually was intending to return 0 only if the condition was true, did you?
>> You should also get a warning (at least in C++) saying that not all control paths return a value.
Technically you should not get a warning if you don't include a return value at the end of main. There is a rule in C++ that allows you to leave out the return statement and the compiler will implement a return 0 automatically.
Of course, using a return value inside the if and not after it is confusing even if it is technically correct, so the advice is still appropriate.
Thats right Elysia.. True, I will put return outside the if statement.
And it´s right about the if condition it should ofcourse be inside the while loop as it in realtime searching for the greatest timevalue.
Now it works and I appreciate all help that I got. I will now experiment and learn all the logics with the code, and the indentations.. Take care...
Last edited by Coding; 12-18-2007 at 04:54 PM.