I'm trying to use string input (yes or no) as a sentinel for a loop. The loop repeats a switch statement, and at the end prompts the user with a yes or no question. Until they type 'yes' as their answer, the loop continues to receive data from the user. The problem comes from trying to receive a new value for the sentinel.
***Reviewed the comments and made some changes. Here's the updated code:
Scanner input = new Scanner ( System.in );
System.out.print( "Please enter a product number, 1 - 5: ");
int product = input.nextInt();
double sum = 0;
boolean complete = false;
while (!complete) {
switch (product){
case 1: sum = sum + 2.98;
break;
case 2: sum = sum + 4.50;
break;
case 3: sum = sum + 9.98;
break;
case 4: sum = sum + 4.49;
break;
case 5: sum = sum + 6.87;
break;
}
System.out.print( "Is your order complete? Please type true or false:");
complete = in.nextLine();
}
All of that is working but I am still having trouble with the prompt to break the sentinel. I'm trying to get it set up to where the user types true to end the loop or false to continue it. I'm starting to think I've overlooked something. I greatly appreciate the help, thank you.