Java election, arrays keep tally of votes?

Posted 28 June 2011 - 12:21 PM

The point of this program is that there are ten people, marked 0 -9 and it should count the votes for each. input is a list of numbers from 0-9 ended with a flag, so a value of one entered means person 1 gets a vote. The array should keep track of the votes.

This is a pretty rough start on my code, and my output is producing 0 for every single count.

Re: Java election, arrays keep tally of votes?

Posted 28 June 2011 - 12:41 PM

by the way, I forgot to add that I don't want to use .parse
The input can be virtually unlimited (a list of numbers from 0-9. e.g. 8 6 5 7 5 3 0 9 4 3 5 7 3 2 5 5 -999
Do I even need a for loop? I just don't understand how assign each vote to the array[0], array [1], etc...

Re: Java election, arrays keep tally of votes?

Posted 28 June 2011 - 12:59 PM

Hint- use a for loop. This for loop will iterate through the entire array. The i variable is the index of the element in the array. Now just assign a single piece of input (scan.nextInt()) to the element in the loop.

Re: Java election, arrays keep tally of votes?

Posted 28 June 2011 - 01:05 PM

You're on the right track. One thing- votes has a static value. It is the first number you read in. Don't you want to keep reading in the next inputs specified? If so, you want to assign scan.nextInt() to the elements, not votes.

Re: Java election, arrays keep tally of votes?

Posted 28 June 2011 - 02:09 PM

The point of this program is that there are ten people, marked 0 -9 and it should count the votes for each. Input is a list of numbers from 0-9 ended with a flag, so a value of 1 entered means person 1 gets a vote. The array should keep track of the votes. I'm kind of confused about how to incorporate the flag, and MAJORLY confused about how to assign input ( such as 3) to count as a vote for candidate [3]. Any thought??