I need to make a program that reads a .txt file of a 2-D array and returns the results of an election.
Sample input – votes.txt
3
4
20 34 24 16
13 36 89 20
27 80 76 46
Sample Output
Election Results
----------------------------------------------------
State1 was won by Party C
State2 was won by Party C
State3 was won by Party B
State4 was won by Party C
3
Election Results by Party
----------------------------------------------------
Party #states won
A 0
B 1
C 3
Party C has won the election, winning 3 states.
2) "It will not run" isn't exactly a helpful description of the problem. What behaviour are you seeing? How does it differ from the expected behaviour? What error messages are you getting? Help us to help you.
fscanf(ifp, "%d", &ROWS);
fscanf(ifp, "%d", &COLS);
int k;
int voting[ROWS][COLS],i,j;
char party[ROWS];
This is illegal in C++. You must declare the size of arrays using constants that are known at compile-time.
(It's also badly formatted. Seriously, you'll find it much easier to read and understand your own code if you use consistent indentation.)
If your code is crashing, the best thing you can do is use your debugger to step through it, find out where it's crashing, and inspect the contents of the memory at that point. The debugger is one of the most useful tools in the developer's armoury.