I need to write a program using only if else statements that prompts a user to enter an account number and beginning balances. Account number needs to be between 1000 and 9999 and balance should not be negative.
I have this first part done.
The next part says "Continue with the program only if the account numbers and balances are valid for both accounts."
We are not allowed to use loops, only if-else statements. Anyone know how I can do this?
A simple, though probably inelegant, way to do this is to use your || and && operators.
For example:
1 2 3 4
if ((accountNumber >= 1000 && accountNumber <= 9999) && balance >= 0)
{
// Some code.
}
If you need to validate the account number and balance separately, you can nest the ifs. The problem is that without a loop, this check will only be performed once. If an invalid account number or balance is entered, it will skip whatever code is supposed to be performed if the information is valid and continue on with whatever comes next in your program.