I need to create a function that uses a loop.
This function will open a text file and then must be able to skip a variable number of leading random integers. The program must be able to handle any number of leading random integers.
Example if the opened file reads this on its first line:
100 120 92 82 38 49 102
and the SKIP_NUMBER variable is assigned 3 the number the function would grab is 82.

The function must continue to grab the integers every SKIP_NUMBER until it reaches the end of the file.
These integers taken from the txt file are then placed into another text file.

Please help I'm really lost on how to create this loop! :D

Here is my finction so far...
________________________________________-
//Function skips variables and returns needed integer
int skipVariable (int SKIP_NUMBER)
{

return 0; //temporary return
}
____________________________________
These are my program variables:

// initalize function/variables

ifstream fin;
string IN_FILE_NAME, OUT_FILE_NAME;
int SKIP_NUMBER;

Recommended Answers

All 2 Replies

Hints :

1) Make use of for loops
2) Make use of the mod, % , operator

very simple -- read and discard all the numbers up to the one you want to keep. A loop will be handy for that.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.