|storing the integers in a vector and then immediately calculating by starting at the back of the first fraction and iterating back through the numbers (using the reciprocal and the previous number at every iteration)|
Yes, that's certainly one way of doing it, if there is no pattern to the input data. See:
However, you need to read your integers first AND CHECK THEM (just write them out).
Just by inspection of your code (which plainly won't compile):
- you are pushing back into a vector<int> called integers
that you haven't defined
- you changed your input file stream from input_file
... and then, bizarrely, to idk
- you didn't declare variable next
(as a string)
- you have incorrect syntax in getline
(missing a comma between arguments) on line 26
- you should test the state of the stream after an attempted read, not use eof
to detect end of file
- if you don't know why you are using an included header then don't do so (tell me why you think you will use random
You appear to be cobbling together code from other examples without much understanding of what it is doing.
You should fix the file reading first, before you even think about evaluating continued fractions. Check all the integers that you (think you have) read, by writing them out to screen. Only after that should you worry about continued fractions. When you do get to that stage, be careful with integer division.
You can check your continued fractions when you finally get to them, because the examples that you give are (truncated) values of pi, square root of 2 and e.