I'm trying to write a program that reads the data below from an input file, planetsinput.txt, computes the density for each planet and prints the answer to an output file, planetsoutput.txt, along with the highest and lowest values.
Currently I have everything working except for the fact that I'm getting an incorrect output for max and min.
The ! takes a bool operand. Therefore, the k is implicitly converted first to bool. The ! negates the boolean value. Then the bool is converted back to integral value in order to do the array indexing.
However, wouldn't it be more logical to compare to max_x, if the intent is to determine whether max_x has to be updated?
There is also the other way: max_x = *std::max_element( density, density + ???? );
The ???? above is, because your line 25 is bad. Are you really creating a 0 element long array?