Please help, I have done the entire project but I am running intoan error. This
ID: 3609096 • Letter: P
Question
Please help, I have done the entire project but I am running intoan error.This is my code:
#include<iostream>
#include<conio.h>
using namespace std;
struct BankAccount
{
int AccountNumber;
double AccountBalance;
};
int main()
{
BankAccount firstAccount;
BankAccount secondAccount;
cout<<"Please enter the first accountnumber"<<endl;
cin>>firstAccount.AccountNumber;
while(firstAccount.AccountNumber < 1000 ||firstAccount.AccountNumber > 9999 )
{
cout<<"Invalid accountnumber please try again."<<endl;
cin>>firstAccount.AccountNumber;
}
cout<<"Please enter the second accountnumber"<<endl;
cin>>secondAccount.AccountNumber;
while(secondAccount.AccountNumber < 1000 ||secondAccount.AccountNumber > 9999 ||secondAccount.AccountNumber == firstAccount.AccountNumber)
{
cout<<"Invalid accountnumber please try again."<<endl;
cin>>secondAccount.AccountNumber;
}
cout<<"Please enter the beginning balancefor the first acccount"<<endl;
cin>>firstAccount.AccountBalance;
while(firstAccount.AccountBalance < 0)
{
cout<<"Invalid balanceplease try again."<<endl;
cin>>firstAccount.AccountBalance;
}
cout<<"Please enter the beginning balancefor the second acccount"<<endl;
cin>>secondAccount.AccountBalance;
while(secondAccount.AccountBalance < 0)
{
cout<<"Invalid balanceplease try again."<<endl;
cin>>secondAccount.AccountBalance;
}
double amount;
cout<<"Please enter the amount to transferfrom the first to second account:"<<endl;
cin>>amount;
while(amount <= 0)
{
cout<<"Invalid amountplease try again."<<endl;
cin>>amount;
}
if (firstAccount.AccountBalance - amount >=0){
firstAccount.AccountBalance =firstAccount.AccountBalance - amount;
secondAccount.AccountBalance= secondAccount.AccountBalance + amount;
if(firstAccount.AccountBalance - amount < 10){
cout<<"Warning: Less than $10 remains in account 1"<< endl;
}
if(secondAccount.AccountBalance + firstAccount.AccountBalance>= 100000){
cout<<"Warning: The amount in the second account hasexceeded $100,000 Therfore your balance is no longer federallyinsured."<<endl;
}
cout<<"Amount in firstaccount ("<<firstAccount.AccountNumber<<") is now:$"<<firstAccount.AccountBalance<<endl;
cout<<"Amount in secondaccount ("<<secondAccount.AccountNumber<<") is now:$"<<secondAccount.AccountBalance<<endl;
}
else{
cout << "Transfercannot be completed, insufficient funds.)" << endl;
}
system("pause");
}
Everything is working as it should but there is one problem.
this part:
if (firstAccount.AccountBalance - amount < 10){
cout<<"Warning: Less than $10 remains in account 1"<< endl;
}
does not work correctly.
If you input two account numbers and you input a balance for eachone such as
account 1: $500
account 2: $320
and you transfer 480 from account one to account two you'll noticethat math is done correctly but the message "Warning: Less than $10remains in account 1" is displayed even though you have $20 left inaccount 1
what am i doing wrong?
this is what i need it to do:
Issue a warning message if the transfer causes the balance in thefirst account to drop below $10, but make the transfer.
Please help asap and I will award lifesaver points. thanks