I need help getting this loop to work. It may be because I don't really know how to use loops or the if statements. But I think I needed to use the If statements when it comes to receiving a free yogurt after 10.
import java.util.Scanner;
public class Foothill {
public static void main(String args[]){
Scanner scanner = new Scanner(System.in);
int numPurchases, totalPurchased;
boolean correct;
String menu;
numPurchases = 0;
totalPurchased = 0;
correct = false;
while(!correct)
{
System.out.println("Menu:");
System.out.println(" P (Process Purchase)");
System.out.println(" S (Shut down)");
menu = scanner.nextLine();
if (menu.charAt(0)=='S' || menu.charAt(0)=='s'){
System.exit(0);
} else if (menu.charAt(0)=='P' || menu.charAt(0)=='p'){
continue;
}
System.out.println("Your choice: " + menu.charAt(0));
System.out.println("How many yougurts would you like to buy?");
numPurchases = scanner.nextInt();
totalPurchased += numPurchases;
if (totalPurchased > 0 || totalPurchased < 10){
System.out.println("you have purchased " + totalPurchased + " yogurts");
} else if (totalPurchased >= 10){
System.out.println("Congradulations you have recieve a free Yogurt");
System.out.println("Remainding yogurt credits: " + (totalPurchased-10));
}
}
}
}
I don't really know how to use loops that well so that may be my problem because I have never made a loop using false and true