Does anyone know why the first condition is being skipped by Java?
while((withdraw % 100) != 0 && (withdraw > startBalance))
Although I state that the withdrawal must be less than the startBalance
, you can still type a number that is higher than the startBalance
and the the newBalance
will be negative.
Here's my code:
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int startBalance = 1000;
System.out.println("Please enter how much you want to withdraw: ");
int withdraw = input.nextInt();
while((withdraw % 100) != 0 && (withdraw > startBalance)){
System.out.println("Sorry, you can only withdraw a value multiple of 100 (we only have 100 SEK bills): ");
withdraw = input.nextInt();
}
int newBalance = startBalance-withdraw;
System.out.println("Thanks! Your new balance is: SEK " + newBalance);
}