Hi,

Im a new beginner to C++ and i have a question.
I have a .txt document with many different values.
I would like to return a value from the .txt file depending on what value i give in.

I want to pass how many lines in the .txt file.
eg. text file contains:

5 (lines in .txt file)
10000
1000
100
10
0

and my test values are:
0.04
0.03
0.02
0.01
0

If I pass 0.02 function should return 100. 0.03 should return 1000.

Can anyone give me a good example of this?

Best regards

Just multiply the parameter by 100 to get a whole integer, then return the line in the file which has that many digits. Is the file already sorted in numeric value in descending order? If not, then you will probably have to read the entire file and pick out the …

## All 4 Replies

why are you passing fractional values instead of whole numbers. When you pass 0.02 does that mean to get the line that contains 2 zeros, e.g. 100? Then why not just pass 2 instead of 0.02?

The reason why im passing fractional values is because I want to pass ullage to the function and return volume from a .txt file. The txt file is actually a volume table.

Maybe I will need to pass step value to the function as well?

Any example will be appreciated.

Best regards

Just multiply the parameter by 100 to get a whole integer, then return the line in the file which has that many digits. Is the file already sorted in numeric value in descending order? If not, then you will probably have to read the entire file and pick out the lines that you want.

Hi Ancient Dragon,