the code that i have written is for an app that is similar to a pseudo ATM, where if the user inputs the specified pin they get access to the account details. This is very early stages but the main issue i am running into is that when the correct pin is put in and the user is given prompt for what they want to do next through the Please select what you want to do line if the user is to select for example Inquire Balance they are presented with the current balance being 10000.0. The java then loops back to the original loop meaning the user has to put in the pin again. What i want to do is for the user to be presented with the menu again inquiring what they want to do after they are shown the information they need.
This is the code i have written.
class app {
public static void main(String[] args) {
long pin = 2927942074l;
double balance = 10000.0;
int attempts = 3;
System.out.println("Please enter your pin.");
while (attempts > 0) {
Scanner keyboardpin = new Scanner(System.in);
long input = keyboardpin.nextLong();
if (input == pin) {
System.out.println("Correct");
System.out.println("Welcome to your ATM");
int a = 1;
int b = 2;
int c = 3;
int d = 0;
System.out.println(a + " - Inquire Balance");
System.out.println(b + " - Withdraw");
System.out.println(c + " - Deposit");
System.out.println(d + " - Quit");
System.out.println("Please select what you want to do.");
Scanner menuselect = new Scanner(System.in);
int menuinput = menuselect.nextInt();
if (menuinput == a) {
System.out.println(balance);
continue;
}
if (menuinput == b) {
System.out.println("Please enter a withdrawal amount.");
Scanner withdrawamount = new Scanner(System.in);
float withdrawbalace = withdrawamount.nextFloat();
double balancex = (balance - withdrawbalace);
System.out.println("Youre new balance is " + balancex);
if (balancex < balance)
System.out.println("Insufficient balance");
}
} else {
System.out.println("Wrong");
attempts--;
System.out.println("You have " + attempts + " attempts remaining.");
}
if (attempts == 0) {
System.out.println("Maximum number of attempts exceeded");
}
}
}
}
I've tried messing around with the continue function but am not sure if i am using it right. All feedback is appreciated.
break) and second for the "main menu".