unsignedshort bal,totChk, totDep;//account number,balance, total checks, total deposits
float newBal, ovrBal;//new balance, overdrawn balance if account is overdrawn
//Prompt reader for inputs
cout<<" This program will determine if you "
<<" have overdrawn your checking account "<<endl;
cout<<" Begin by entering your 5-digit account number "<<endl;
cout<<" Enter your balance at the beginnning of the month "<<endl;
cout<<" Enter the total of all checks written this month "<<endl;
cout<<" Enter the total of all deposits credited to your account this month "<<endl;
//Calculate new balance
cout<<" Total Balance for account number "<<accNum<<endl;
cout<<" Is: "<<newBal<<" Dollars"<<endl;
//Charge account $17.50 if overdrawn
cout<<" Your account has been overdrawn "
<<" A fee of $17.50 has been charged "<<endl;
cout<<" Your new account balance is "<<endl;
I've tried adding something like
1 2 3 4
cout<<" Account numbers are five digits long "<<endl;
But it still allows me to enter more and less than 5 digits.
So when you entered a number less than 9999 it asked for another and then went to the next statement right? If I understand right, it's not supposed to ask again. So first you need to reverse the condition
if(accNum < 0 || accNum > 9999)
Also to get it to continue asking until a right number is input, you need to use a loop or it will only ask once before going to the next statement.
for loops are used mainly when you know how many times you need to iterate through the loop so that's not really appropriate in this case. Most people would use a do/while loop, but I generally would just use a while loop for this.
Also, those values don't work to only accept 5 digit numbers, but I'm sure you can figure out how to change them on your own.
True, but can you give an instance of an account number that does? It would be more likely that it contained letters and my first thought was to use string instead of int, that way you only needed to check its length. In my opinion that's over complicating this problem though.