Deleted

Last edited on
Can you show us some of the text file?
I'm trying to get the code to work regardless of how many rows or columns are in the text file.

If I may, that seems an unnecessary effort: you know how many columns are there in the file, i.e. 4.

Anyway, I don't think you should use separate variables. I think you'd do better by std::vectors, std::arrays or C-style arrays.

But you need to output also "the percentage of the total votes received", so a single variables to store the sum of all votes could be taken into consideration.

- - -
To check if a stream has opened successfully, you can verify its status simply by:
1
2
3
4
    std::ifstream infile("votesimple.txt");
    if (!infile) {  // if infile didn't opened correctly
        // ...
    }

Topic archived. No new replies allowed.