I am writing a program that calculates the bill when buying eggs by the dozen. I have for the most part figured out most of the code but, I am getting an error message that is saying "variable price might not have been initialized.
Here is the code please help me.
public class BuyingEggs
{
public static void main(String[] args)
{
int eggs; //number eggs to purchase
int dozen; //how many dozen in egg purchase
double price; //price of eggs
double bill; //total cost of purchase
double extra; // how much extra eggs cost
System.out.print("Enter number of eggs: ");
eggs = Input.readInt();
dozen = eggs/12;
if (dozen >= 11)
{
price = 0.35;
extra = 0.029;
}
else if (dozen < 11)
{
price = 0.40;
extra = 0.033;
}
else if (dozen < 6)
{
price = 0.45;
extra = 0.037;
}
else if (dozen < 4)
{
price = 0.50;
extra = 0.041;
}
bill = price * eggs;
System.out.println("Enter number of eggs: " + eggs);
System.out.println("Your cost is $ " + price);
System.out.println("Your bill comes to $" + bill);
System.out.println();
System.out.println("end of program");
} //end main
} //end class BuyingEggs
Thank You in advance!!!! :lol: