Home » .Net

C# program to make a simple ATM machine

In this C# program, we are going to learn how to make a simple ATM based program with basic operations like check balance, withdraw money, deposit money, change PIN number etc?
Submitted by Ridhima Agarwal, on October 18, 2017

In this solution, we will learn how an ATM functions? Just like our daily operations we are implementing the same features in this program, like: deposit cash, withdraw money, check balance, change PIN number etc.

Firstly, a predefined PIN is initialized in this program, so that it can be matched with the given (input) PIN number. And then we select the operations given in the program. Based on the selected operation program will work.

ATM Machine program in C#.Net

using System;
namespace atm_program
{
	class ab
	{
		static void Main(String[] args)
		{
			int amt=10000,a,current,pin=4040,pin1,pin2;

			//read PIN
			Console.WriteLine("Enter the pin");
			pin1=int.Parse(Console.ReadLine());

			//compare PIN
			if(pin1==pin)
			{
				Console.WriteLine("1.To check balance");
				Console.WriteLine("2.To withdraw money");
				Console.WriteLine("3.To deposite Money");
				Console.WriteLine("4.To change the pin");
				Console.WriteLine("Enter your choice");
				int ch=int.Parse(Console.ReadLine());
				switch(ch)
				{
					case 1:
						Console.WriteLine("The current balance in your account is"+amt);
					break;
					
					case 2:
					Console.WriteLine("Enter the amount to withdraw");
					{
						a=int.Parse(Console.ReadLine());
						if(amt>=a)
						{
							if(a%100==0)
							{
								Console.WriteLine("Please collect the cash"+a);
								current=amt-a;
								Console.WriteLine("The current balance is now"+current);
							}
							else
								Console.WriteLine("Please enter the amount to withdraw in the multiples of 100");
						}
						else
						Console.WriteLine("Your account does not have sufficient balance");
					}

					break;

					case 3:
					Console.WriteLine("Enter the amount to be deposite");
					a=int.Parse(Console.ReadLine());
					current=amt+a;
					Console.WriteLine("The current balance in the account is"+current);
					break;
					
					case 4:
					Console.WriteLine("Want to change your pin");
					Console.WriteLine("Enter your previous pin");
					int prepin=int.Parse(Console.ReadLine());
					if(prepin==pin)
					{
						Console.WriteLine("Enter your new pin");
						pin2=int.Parse(Console.ReadLine());
						pin1=pin2;
						Console.WriteLine("Your pin is changed");
					}
					else
						Console.WriteLine("Enter your correct pin");
					break;
					
					default:
					Console.WriteLine("Please select correct option");
					break;
				}
			}
			else
				Console.WriteLine("Pin is wrong");
		}
	}
}

Output

atm program in C# -1
atm program in C# -2





Comments and Discussions

Ad: Are you a blogger? Join our Blogging forum.
Learn PCB Designing: PCB DESIGNING TUTORIAL




Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates


© https://www.includehelp.com some rights reserved.