import java.text.DecimalFormat; import java.util.Scanner; public class SoftwareSales { public static void main(String[] args) { DecimalFormat money = new DecimalFormat("#,###.00"); final double unitPrice = 99.00; int units; double discountPercent, discount, cost; Scanner keyboard = new Scanner(System.in); //ask user enter units System.out.print("Enter the amount of units sold: "); units = keyboard.nextInt(); //algorithm if (units >= 100) {discountPercent = 0.5;} else if (units >= 50 && units <= 99) {discountPercent = 0.4;} else if (units >= 20 && units <= 49) {discountPercent = 0.3;} else if (units >= 10 && units <= 19) {discountPercent = 0.2;} discount = units * unitPrice * discountPercent; cost = (units * unitPrice) - discount; //display System.out.println("Units sold: " + units); System.out.println("Discount $: " + money.format(discount)); System.out.println("Cost $: " + money.format(cost)); } }
I keep getting this error message when I compile the program:
SoftwareSales.java:31: error: variable discountPercent might not have been initialized discount = units * unitPrice * discountPercent; ^ 1 error