QUOTE(HangTight @ 10 Oct, 2008 - 09:21 PM)

I'm trying to make my program loop, that will allow users to go back to the main screen if they choose option 1, 2, or 3. And if you choose option 4 you just end the program. This is what I have so far, Im not even sure if Im using the right loop method.
CODE
import java.util.Scanner;
public class Bank11 {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
do {
double balance = 3500;
double amount;
System.out.println ("1.Dept");
System.out.println ("2.Withdrawal");
System.out.println ("3.Your Balance");
System.out.println ("4.Exit");
int num = scan.nextInt();
if(num == 1)
{
System.out.println ("Deposit Amount?");
amount = scan.nextDouble();
startingBalance = startingBalance + amount;
System.out.println("Balance IS");
System.out.println(balance);
}
else if (num == 2)
{
System.out.println("Witdraw Amount?");
amount = scan.nextDouble();
startingBalance = startingBalance - amount;
System.out.println("Balance is");
System.out.println(balance);
}
else if (num == 3)
{
System.out.println("Your Balance");
System.out.println(balance);
}
else if (num == 4)
{
} while (int = 1, 2, 3)
System.out.println ("See Yea!");
}
}
}
Change the while (int = 1, 2, 3) to while (num !=4)
That should work!
Edit: You should declare balance outside of the do while loop, or else your balance will reset every loop. Not a bad idea if you want to give me a million bucks more everytime I make a withdrawal! =p
Also, you may want to try using a switch statement instead of if-else. I find that easier to write and read too.
This post has been edited by Ephemeralz: 10 Oct, 2008 - 10:16 PM