Hi, I'm having trouble with my program.
It's supposed to tell the user if his bank account has been overdrawn
and if it has then a charge of $17.50 is added to the account balance.
The user should input:
1. The account number which can only be 5 digits long
So how would i add validation to make sure the account number entered can only be 5 digits only?
2.Users balance at beginning of the month
3. Total amount of all checks made during month(amount spent)
4. Total deposits user has made this month
If the new account balance is -5 and the overdrawn charge of 17.50 is added
the program only outputs the new balance as -22.5 instead of -22.50.
The inputs are all supposed to be read in as unsigned shorts and doubles cannot be used.
What i have so far
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
|
//Libraries
#include <iostream>
#include <iomanip>
using namespace std;
//no global variables
//no function prototypes
//Begin execution
int main(){
//Declare variables
unsigned short accNum, 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<<endl;
cout<<" Begin by entering your 5-digit account number "<<endl;
cin>>accNum;
//ADD VALIDATION CHECKING FOR ACC NUM
cout<<" Enter your balance at the beginnning of the month "<<endl;
cin>>bal;
cout<<" Enter the total of all checks written this month "<<endl;
cin>>totChk;
cout<<" Enter the total of all deposits credited to your account this month "<<endl;
cin>>totDep;
//Calculate new balance
newBal=bal+(totDep-totChk);
cout<<" Your New Total Balance is "
<<newBal<<endl;
//Charge account $17.50 if overdrawn
if(newBal<0){
cout<<" Your account has been overdrawn "
<<" A fee of $17.50 has been charged "<<endl;
cout<<" Your new account balance is "<<endl;
ovrBal=newBal-17.50;
cout<<ovrBal;
}
|