I am taking beginning C++ class for work and I am having major issues on my lab right now. We need to read numbers from an input file and write every nth number from that input file to an output file.
For some reason I am reading just the last quarter of the file only and it is not skipping any of the numbers.
So I made an indexNumber that starts at 1 and increments each time the while statement runs. I check to see if it is divisible by the skipNum which is the amount of numbers needed to skip and then if it is divisible by that number I grab the number and read it and then output it to consol. I am skipping the output portion to the new file for now until I get this part working.Code:while ( inF.good() ) { if ( (indexNumber % (skipNum + 1)) == 0 ) { inF >> currentNumber; cout << currentNumber << endl; } indexNumber++; }
Anyone have any ideas of what I am doing wrong?
Edit: Oh yeah and if I do a cout << indexNumber << endl;
it prints incredibly large numbers and starts at 15628 even though it is initialized at 1 at the beginning. Is it working and the consol window just can only display so many lines before they disappear?
Edit2: Another thing when I print out the indexNumber it prints out 5 times for every time the input number prints. ... hmm there seems to be a clue there.
XI Wiki

