The multiple if-else statements for money transactions C++ code sample

 

Compiler: Visual C++ Express Edition 2005

Compiled on Platform: Windows XP Pro SP2

Header file: Standard

Additional project setting: Set project to be compiled as C++

Project -> your_project_name Properties -> Configuration Properties -> C/C++ -> Advanced -> Compiled As: Compiled as C++ Code (/TP)

Other info: none

To do: Listing several money transactions menu using the multiple if-else statements in C++ programming

To show: How to list several money transactions menu using the multiple if-else statements in C++ programming

 

// the if-else statement. This program is to test whether a banking transaction is a deposit,

// withdrawal, transfer or an invalid transaction, and to take the necessary action.

#include <iostream>

using namespace std;

 

int main(void)

{

float amount;

char transaction_code;

 

cout<<"D - Cash Deposit, W - Cash Withdrawal, T - Cash Transfer\n";

// enter the input

cout<<"\nEnter the transaction code(D, W, T); ";

// read the input

cin>>transaction_code;

 

if (transaction_code == 'D' || 'd')

{

cout<<"\nDeposit transaction";

cout<<"\nEnter amount: ";

cin>>amount;

cout<<"\nPROCESSING....Please Wait";

cout<<"\nAmount deposited: "<<amount;

cout<<"\n---THANK YOU! ---";

}

else

if (transaction_code == 'W' || 'w')

{

cout<<"\nWithdrawal transaction";

cout<<"\nEnter amount: ";

cin>>amount;

cout<<"\nPROCESSING....Please Wait";

cout<<"\nAmount withdrawn: "<<amount;

cout<<"\n--- THANK YOU! ---";

}

else

if (transaction_code == 'T' || 't')

{

cout<<"\nTransfer transaction";

cout<<"\nEnter amount: ";

cin>>amount;

cout<<"\nPROCESSING....Please Wait";

cout<<"\nAmount transferred: "<<amount;

cout<<"\n--- THANK YOU! ---";

}

else {

cout<<"\nInvalid transaction!!";

cout<<"D = Deposit, W = Withdrawal, T = Transfer";

cout<<"\nPlease enters the correct transaction code: ";

}

cout<<"\n";

 

return 0;

}

 

Output examples:

 

D - Cash Deposit, W - Cash Withdrawal, T - Cash Transfer

Enter the transaction code(D, W, T); d

Deposit transaction

Enter amount: 2050

PROCESSING....Please Wait

Amount deposited: 2050

---THANK YOU! ---

Press any key to continue . . .

 

D - Cash Deposit, W - Cash Withdrawal, T - Cash Transfer

Enter the transaction code(D, W, T); W

Deposit transaction

Enter amount: 4070

PROCESSING....Please Wait

Amount withdrawn: 4070

---THANK YOU! ---

Press any key to continue . . .

 

D - Cash Deposit, W - Cash Withdrawal, T - Cash Transfer

Enter the transaction code(D, W, T); t

Deposit transaction

Enter amount: 1000000

PROCESSING....Please Wait

Amount transferred: 1e+006

---THANK YOU! ---

Press any key to continue . . .

 

 

C and C++ Programming Resources | C & C++ Code Example Index