I have been working on this assignment for over a week and I have gotten to a point where I am completely stuck. I am trying to read line-by-line when asking the user to enter the amount of votes. I have figured out how to write only the first line of the input file, now I'm trying to do that with the rest of the lines. Any help is greatly appreciated, I've searched the internet and am completely stuck.
My input file that is used, has the following information:
Spencer Breland
Josh Newcomb
Justin Main
Kyle English
Jamie Thompson
The candidates names are contained within the text file. I assume you need to use that data to populate a list of names.
Instead, the candidates names have actually been typed into the program code, multiple times. Even if you didn't have a data file, that would still be an undesirable approach. It is heavy on maintenance, if a candidate withdraws or is replaced by a different one, the program would need to be changed in multiple different places.
As a starting point, define string variables for the names of the list of candidates. That way, you would need to type the candidates names just once, not five times.
When you've done that, modify the code which reads the file, so that it stores the names in your variables.
The one question I have is this: how do we know how many candidates there are? The program assumes five. Perhaps there is some rule which says there must always be exactly five candidates, but in real elections, the number of candidates may vary, therefore the program should be driven by the data file, the number of lines in the file will control how many times the user is prompted to enter the votes.