It only includes 60 because of your other problem of not adding the braces. Notice how it outputs 24:59, but there isn't supposed to be a 24 hour either.
To fix your problem, just add braces around the code that belongs in the loop. The first step is to identify which code belongs in the loop. Can you identify the lines of code you think need to be repeated each time and therefore belong in the loop?
The syntax of a for loop is:You are missing the blue things.Code:for (blah; blah; blah) { // code goes here // and repeats // each time in the loop. }
Personally I think this when you tell me that:
But I think that only does one of the for loops, aye?Code:#include <iostream> #include <fstream> #include <iomanip> using namespace std; int main () { int hh; int mm; ofstream myfile; myfile.open ("TimeStamps.txt"); for ( mm = 0 ; mm < 59 ; mm++) for ( hh = 0 ; hh < 24 ; hh++) {cout.fill('0'); myfile.fill('0'); myfile << setw(2) << hh << ":" << mm; } cout.fill(' '); myfile.fill(' '); myfile.close();
edit: that fills my text file with a huge amount of ''''''''''''''s
Last edited by Roflcopter; 10-11-2007 at 05:23 PM.
That looks good to me for the inner loop.
You would normally add the braces for each for loop separately. You want the outer for loop to contain the entire inner for loop, so you would add the starting brace before the second for statement (the start of the inner loop) and the closing brace after the closing brace of the inner loop (which is the end of the inner loop). In this case it actually isn't needed, since that whole block is counted as one block and is all repeated anyway, but for clarity and good practice you should add those braces.
As for the output in the file, that is really weird. It happens for me when I use notepad to open it, but not when I open it with another editor. Try adding a newline or space after the minute is output, then you should be able to see it better.
I'm going to follow what seems to be forum etiquette and not flat out do it for you, but I will fix your tab problem, then you should be able to see the problem easier:
Code:#include <iostream> #include <fstream> #include <iomanip> using namespace std; int main () { int hh; int mm; ofstream myfile; myfile.open ("TimeStamps.txt"); for ( mm = 0 ; mm < 59 ; mm++) for ( hh = 0 ; hh < 24 ; hh++) { cout.fill('0'); myfile.fill('0'); myfile << setw(2) << hh << ":" << mm; } cout.fill(' '); myfile.fill(' '); myfile.close(); ...