Q:

C# program to demonstrate ATM transactions

0

C# program to demonstrate ATM transactions

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Program:

The source code to demonstrate the ATM transaction in C# is given below. The given program is compiled and executed successfully on Microsoft Visual Studio.

//Program to demonstrate ATM transaction in C#.

using System;

class ATMDemo
{
    public static void Main()
    {
        int totalBalance    = 50000;
        int depositAmount   = 0; 
        int withdrawAmount  = 0;

        int option;
            
        int Atmpin = 0;
        
        Console.Write("Enter Your ATM Pin: ");
        Atmpin = int.Parse(Console.ReadLine());

        if (Atmpin == 1234)
        {
            Console.WriteLine("#########Select ATM Service##########\n");
            Console.WriteLine("1. Balance Enquiry\n");
            Console.WriteLine("2. Cash Withdrawal\n");
            Console.WriteLine("3. Deposit your Cash\n");
            Console.WriteLine("4. Exit\n");
            Console.WriteLine("#####################################\n\n");
            Console.Write("Select option: ");

            option = int.Parse(Console.ReadLine());

            switch (option)
            {
                case 1:
                    Console.Write("\nYour Total Account Balanace : "+totalBalance);
                    break;
                case 2:
                    Console.Write("\nEnter withdrawal amount: ");
                    withdrawAmount = int.Parse(Console.ReadLine());

                    if (withdrawAmount % 100 != 0)
                    {
                        Console.WriteLine("\nPlease enter withdrawal amount in multiple of 100");
                    }
                    else if (withdrawAmount > totalBalance)
                    {
                        Console.WriteLine("\nIn-sufficient balance in your account");
                    }
                    else
                    {
                        totalBalance = totalBalance - withdrawAmount;
                        Console.WriteLine("\n\nPlease collect your money");
                        Console.WriteLine("\nYour remaining balance is: "+totalBalance);
                    }
                    break;
                case 3:
                    Console.Write("\nEnter amount to deposit: ");
                    depositAmount = int.Parse(Console.ReadLine());
                    totalBalance = totalBalance + depositAmount;
                    Console.WriteLine("Your current balance: "+totalBalance);
                    break;
                case 4:
                    Console.WriteLine("\nInvalid Option");
                    break;
            }
        }
        else
        {
            Console.WriteLine("Invalid Pin Number");
        }
        Console.WriteLine("\n\nTHANKS FOR USING OUT ATM SERVICE");
    }
}

Output:

Enter Your ATM Pin: 1234
#########Select ATM Service##########

1. Balance Enquiry

2. Cash Withdrawal

3. Deposit your Cash

4. Exit

#####################################


Select option: 2

Enter withdrawal amount: 5000


Please collect your money

Your remaining balance is: 45000

THANKS FOR USING OUT ATM SERVICE
Press any key to continue . . .

Explanation:

In the above program, we created a class ATMDEMO that contains the Main() method. Here we created an ATM menu that provides the following options:

  1. Balance Enquiry
  2. Cash Withdrawal
  3. Deposit your Cash
  4. Exit

Here we take user input for ATM PIN, if ATM PIN is correct then we can use the above options.

Balance Enquiry:

Here we print the total balance of the user.

Cash Withdrawal:

Here we checked entered amount that should be multiple of 100, and check entered amount must be less than total balance, if both conditions are satisfied then we can withdraw the amount from ATM.

Deposit Cash:

Here we took amount as input and add to the total balance and then print total balance on the screen.

Exit:

This option is used to exit from ATM program.

 

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

C# Basic Programs | Class, Object, Methods

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
C# program to generate random numbers... >>
<< C# program to demonstrate the example of Pass by r...