I have no idea where to start on this program. Here are the specifications that I am supposed to include:
The function will determine which candidate won an election. The votes will be represented by an array of integers valued 1 through N, where N is the number of candidates. An integer of 1 denotes a vote for candidate 1 and a 2 denotes a vote for candidate 2, etc. The end of the votes' array are denoted by a 0 which, of course, zero does not correspond to any candidate.
-returns the number of the winner based on candidate numbers 1,2, etc.
-name the function countVotes
-receives the array of votes
-iterates through the votes array to determine the number of candidates(maximum number in array)
-allocates a new array of integers, tallies, to have a size equal to the number of candidates
-initialize each element in the tallies array to be zero
-iterates through the votes array while adding one to tallies array element that corresponds to the vote
~For example, if a vote has a value 3, increment tallies [ 3-1 ]
~One is subtracted in the array notation to account for the array beginning at element 0
-Iterate through the tallies array
~To determine the winner, i.e. which candidate has the maximum tally.
~To print out how many votes each candidate received
-Return the number of the winner based on candidate numbers 1,2, etc.
My professor gave us this code to start out with:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
|
#include <iostream>
using namespace std;
int countVotes(int votes[]);
int main()
{
int election[] = { 3, 4, 2, 4, 3, 1, 2, 4, 3, 3, 3, 2, 1, 4, 0 };
int elected = countVotes(election);
cout << "Candidate " << elected << " won the election.\n";
return 0;
}
int countVotes(int votes[])
{
}
|
please help me!