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

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?

Hi, Thank you for your answer.

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,

Thank you for your answer.

The file is already sorted with the highest number on top and lowest number in bottom according to ullage.

I will try to program it in VS.
Thank you.

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.