I keep getting a "cannot find symbol" error here:
System.out.println ("Are there still more precincts to report? Please enter y or n");
response = scan.next();
while (response.equalsIgnoreCase(y))// Initializations
{
System.out.print("Enter votes for Polly: ");
votesForPolly = scan.nextInt();
System.out.print("Enter votes for Ernest: ");
Here's the full code if the problem lies elsewhere:
import java.util.Scanner;
public class Election
{
public static void main (String[] args)
{
int votesForPolly; // number of votes for Polly in each precinct
int votesForErnest; // number of votes for Ernest in each precinct
int totalPolly; // running total of votes for Polly
int totalErnest; // running total of votes for Ernest
String response; // answer (y or n) to the "more precincts" question
int pollyCarried = 0;
int ernestCarried = 0;
int tied = 0;
Scanner scan = new Scanner(System.in);
System.out.println ();
System.out.println ("Election Day Vote Counting Program");
System.out.println ();
System.out.println ("Are there still more precincts to report? Please enter y or n");
response = scan.next();
while (response.equalsIgnoreCase(y))// Initializations
{
System.out.print("Enter votes for Polly: ");
votesForPolly = scan.nextInt();
System.out.print("Enter votes for Ernest: ");
votesForErnest = scan.nextInt();
totalPolly += votesForPolly;
totalErnest += votesForErnest;
if ( votesForPolly > votesForErnest )
pollyCarried++;
else if ( votesForErnest > votesForPolly )
ernestCarried++;
else
tied++;
System.out.println ("Are there still more precincts to report? Please enter y or n");
response = scan.next();
}// Loop to "process" the votes in each precinct
int totalVotes = votesForPolly + votesForErnest;
System.out.println("Polly got " + totalPolly + " votes carrying " + pollyCarried + " precincts.");// Print out the results
System.out.println("Ernest got " + totalErnest + " votes carrying " + ernestCarried + " precincts.");
System.out.println("Polly got " + ((totalPolly/totalVotes)*100));
System.out.println("Ernest got " + ((totalErnest/totalVotes)*100));
System.out.println("Polly carried " + pollyCarried + " precincts");
System.out.println("Ernest carried " + ernestCarried + "precincts");
System.out.println(tied + " precincts resulted in a tie");
}
}
I've also tried making a char or string called "affirmative" and assigning it the letter y so that I can use it in my loop but it's no good.