I'm writing a program that uses 2 arrays to store names of flowers, and their corresponding prices. I am new to programming so my coding its really hit or miss. I'm receiving a error when trying to run this program. It compiles fine, runs, through the first "enter flower" and "how many" but then gets an error. Where am I off on this? *note I need to add an else factor to this, I just want to iron out the first part of the if statement first
import java.util.*;
public class FlowerCounter {
public static void main(String[] args) {
String types[]={"petunia","pansy","rose","violet","carnation", "lily", "poppy", "daisy", "tulip", "hydrangea" };
double cost[]={.5,.75,1.5,.75,.85,1.25,2.15,.85,2.75,1.30};
double total=0;
int amt,i;
Scanner s=new Scanner(System.in);
String type;
System.out.print("What type of flower would you like? ");
type = s.nextLine();
for(i=0;i<types.length;i++)
if(type.compareToIgnoreCase(types[i])==0) { //comparing the type to the type in the array types
i=types.length; //setting i's length for use with cost
System.out.print("How many "+type+"s would you like? ");
amt= s.nextInt(); //declaring amount
total = total + amt * cost[i];
System.out.print(type + ":" + amt + "at " + cost[i] + " will cost " + total);
}
}
}