I'm writing code to have the user input entrees served on certain days. The error is coming in when I ask the user to search for a certain entrée so I can output the day it's served.
The error I'm getting is java:39: cannot find symbol for this line:
System.out.println(food+" is served on " +day[index]);
symbol: variable index
I accessed the day index earlier in the code without errors, so I'm not sure what's wrong.
import java.util.Scanner; public class Assignment3 { public static void main(String[] args) { //create scanner object Scanner sc = new Scanner(System.in); String food; //create day array String[] day = {"Monday", "Tuesday","Wednesday", "Thursday", "Friday"}; //create entree array String[] entree = new String[5]; //create price array double[] price = new double[5]; //prompt user for input for entree for(int index=0; index < day.length; index++) { System.out.println("What entree is being served on " +day[index]); entree[index]=sc.next(); } //prompt user for price for(int index=0; index < entree.length; index++) { System.out.println("What is the price for "+entree[index]); price[index]=sc.nextDouble(); } System.out.println("Enter an entree to search for:"); food=sc.next(); System.out.println(food+" is served on " +day[index]); //Find the highest priced entree double max = price[0]; for(int index=1; index < price.length; index++) { //examine the current element in the array //determine if it is larger than the current max if(price[index]>max) { //if so, replace the current max max = price[index]; } } System.out.println(); System.out.println("The most expensive entree is " +max); } }