Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

C# “To take away or to give?” A bank maintains three types of accounts namely sa

ID: 3909334 • Letter: C

Question

C#

“To take away or to give?”
A bank maintains three types of accounts namely savings, checking, and loan. Write a C# program that uses a while or do … while loop. Inside the loop, prompt the user to input from the keyboard an account number, an account type (s for savings or d for checking c for loan), current balance, and a deposit amount.
Calculate interest as follows:
For savings accounts, the deposit amount is added to the current balance plus 4% interest on the new balance is added.
For checking accounts, the deposit amount is added to the current balance.
For loans, the deposit amount is subtracted from the current balance.
Display a message to the console window showing the new balance. Here is an example interaction session:


Enter account number: 1111
Enter account type: s
Enter the current balance on the account: 5000
Enter deposit amount: 500
New balance on savings account 1111 is $5,720.00
.
.

Explanation / Answer

The code is commented at required places. Variables are named accordingly.

Code:

using System;

using System.Collections.Generic;

using System.IO;

class Solution {

static void Main(String[] args) {

  

// While Loop

while(true){

// For going outside the loop

Console.Write("Enter any key to continue and 'e' to exit:");

flag= Console.ReadLine();

if(flag=="e"){

break;

}

int Acc;//For account number

string AccType; //For Account Type

double CurBal; //For current balance

double DepAmt; //For deposit amount

double NewBalance=0; //For new balance

  

string UserInput;

//Asking account number

Console.Write("Enter account number: ");

UserInput= Console.ReadLine();

Acc= Convert.ToInt32(UserInput);

  

//Asking account type

Console.Write("Enter account type: ");

AccType= Console.ReadLine();

  

//Asking Current Balance

Console.Write("Enter the current balance in the account: ");

UserInput= Console.ReadLine();

CurBal= Convert.ToDouble(UserInput);

  

//Asking Deposit Amount

Console.Write("Enter deposit amount: ");

UserInput= Console.ReadLine();

DepAmt= Convert.ToDouble(UserInput);

  

if(AccType=="s"){

AccType= "savings";

NewBalance= CurBal+ DepAmt;

NewBalance*=1.04;

}

if(AccType=="d"){

AccType="checking";

NewBalance= CurBal+ DepAmt;

}

if(AccType=="loan"){

  

AccType="loan";

NewBalance= CurBal- DepAmt;

}

Console.WriteLine("New balance on " + AccType+ " account "+ Acc + " is $"+ NewBalance);

}

}

}

Sample Output: