I created a bank app, and when I try to deposit money that is over 10,000, my error message that I set up displays, but any number under works.. I assume this has something to do with value types. I used int, however I tried double but can't figure that out too.
/* FUNCTION DEFINITION */
void DepositMoney(int initialbalance, int deposit);
// Main Program
int main()
{
int initialbalance=10000;
int deposit;
cout << " \t ***** What you want to Do ??? Choose the Action character *****" << endl << endl;
cout <<" \t W : Money Withdraw" << endl
<<"\t D : Deposit" << endl //I CHOSE THIS ONE
<<"\t B : Balance" << endl
<<"\t T : Transfer" << endl
<<"\t C : Change Details" << endl
<<"\t Q : Quit or Exit" << endl << endl ;
string input;
cin >> input;
bool t=true;
if (input=="W" || input=="w"){
cout<<"\n\t Your balance is: " << initialbalance<<endl;
cout<<"\n\t How much would you like to withdraw: ";
cin>> withdraw;
withdrawMoney(initialbalance, withdraw);
initialbalance -= withdraw;
t=false;
}
else if (input=="D" || input=="d"){
cout<<"\n\t Your balance is: " << initialbalance<<endl;
cout<<"\n\t How much would you like to deposit: ";
cin>>deposit;
DepositMoney(initialbalance, deposit);
initialbalance = deposit;
t=false;
// Function for Deposit
void DepositMoney(int initialbalance, int deposit)
{
// Get how much user want to deposit and display balance after adding
if(initialbalance < deposit)
cout <<"\n\t The amount you entered is not not valid."<<endl; //THIS MSG DISPLAYS
else
initialbalance = deposit;
cout<<"\n\t Your new balance is: " << initialbalance <<endl<<endl<<endl;
}
I tried changing every data type that said int to double, but that didn't even run the code.
CodePudding user response:
When you call DepositMoney()
, you have this check: if (initialbalance < deposit)
. At this point, initialbalance
is 10000
, so if the amount is greater, then you cannot deposit it. Based on the logic, you likely wanted a check like that in withdrawMoney()
, not in DepositMoney()
.