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

Q6: Write a C# program to help balance your bank account (assume that the initia

ID: 3859071 • Letter: Q

Question

Q6: Write a C# program to help balance your bank account (assume that the initial balance is 0). The main program should repetitively prompt the user to enter a transaction (char) which could be ‘c’ or ‘C’ for cheque, ‘d’ or ‘D’ for deposit, ‘p’ or ‘P’ for print, and ‘q’ or ‘Q’ for quit. Using a switch statement, select the appropriate action and call the method. The program is to have three user-defined methods: (i) A void method called Cheque which accepts one reference parameter of type double which contains the account balance. Cheque prompts the user for the amount of the cheque and then deducts the amount of the cheque from the balance. A $1 service charge is applied to each cheque. The cheque (and the service charge) should not be applied if it would leave a negative balance and the customer should be warned. The method header should look like: public static void Cheque(ref double balance) (iii) A void function called Deposit which also accepts one reference parameter of type double which stores the account balance. Deposit prompts the user for the amount of the deposit and then adds the amount of the deposit to the balance. If the amount of the deposit is more than $1000, give the customer a 2% bonus on the amount of the withdrawal (e.g., if $2000 is deposited, then add $2040 to the account). The method header should look like: public static void Deposit(ref double balance) (iv) A void function called Print which takes one value parameter of type double which contains the balance and then prints it out. The method header should look like: public static void Print(double balance) The main program should continue until the user enters a ‘Q’ or ‘q’.

Explanation / Answer

#include <stdio.h>

static double accountBalance = 0;
static double chequeServiceCharge = 10;

static void cheque(double chequeAmount) {
   if (accountBalance < chequeAmount) {
       printf(
               "Insuffiecient balance, cannot take cheque request. or cheque bounced ");
   } else {
       accountBalance = accountBalance - chequeServiceCharge;
       if (accountBalance < chequeServiceCharge) {
           printf(
                   "Service charges should be maintanied before issuing any cheque ");
       }
   }

}

static void deposit(double amount) {
   if (amount > 1000) {
       amount = amount + ((amount * 2) / 100);
       accountBalance = accountBalance + amount;
   } else {
       accountBalance = accountBalance + amount;
   }
}

static void print(double balance) {
   printf(" Account balance : %lf ", balance);
}

int main() {
   char choice;
   int wantToContinue = 1;
   while (wantToContinue == 1) {
       printf("Enter a transaction from the following ");
       printf("‘c’ or ‘C’ for cheque ");
       printf("‘d’ or ‘D’ for deposit ");
       printf("‘p’ or ‘P’ for print ");
       printf("‘q’ or ‘Q’ for quit. ");
       printf("Kindly enter the char from the above option ");
       scanf("%c", &choice);
       if (choice == 'c' || choice == 'C' || choice == 'd' || choice == 'D'
               || choice == 'p' || choice == 'P' || choice == 'q'
               || choice == 'Q') {
           printf("You have entered %c ", choice);
           double amount = 0;
           switch (choice) {
           case 'c':
           case 'C':
               printf("Enter the amount of cheque ");
               scanf("%lf", &amount);
               cheque(amount);
               print(amount);
               break;
           case 'd':
           case 'D':
               printf("Enter the amount to be deposited ");
               scanf("%lf", &amount);
               deposit(amount);
               break;
           case 'p' :
           case 'P':
               print(accountBalance);
               break;
           case 'q':
           case 'Q':
               wantToContinue = 0;
               break;
           default:
               printf("End of Program");

           }
       } else {
           printf(
                   "Entered Wrong choice. Please enter the correct transaction");
       }
   }

   return 0;
}

Descrition : Added print method as well