Hi, Im trying to write a program of a salary from a textbook problem, but am having a hard time. Hopefully you can get the gist of the program, I want it to keep asking for items of what the "salesperson" has sold, until an invalid item is entered, where it breaks and does the calculations of $200 + %9 of sales. The loop stops after 1 input, and you have to enter the items value rather than just item1 in the input. I would like to know how to fix this. Thanks!
package rand;
import java.util.Scanner;
public class rand19 {
public static void main(String[] args) {
Scanner input = new Scanner (System.in);
while (true) {
double item1 = 239.99;
double item2 = 129.75;
double item3 = 99.95;
double item4 = 350.89;
double pay = 0.0;
System.out.printf("Enter an item value for the salesperson: ");
double salesperson = input.nextDouble();
if (salesperson == item1) {
pay = pay + item1;
}
else if (salesperson == item2) {
pay = pay + item2;
}
else if (salesperson == item3) {
pay = pay + item3;
}
else if (salesperson == item4) {
pay = pay + item4;
}
else {
break;
}
double basepay = 200;
double basepaypercent = 9 % pay;
double finalpay = 200 + basepaypercent;
System.out.printf("Salespersons earnings: " + finalpay + "\n");
System.out.println("--------------------------------------");
}
}
}