C++ ATM Source Codes

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 3

ATM is an electronic telecommunications device that enables the customers of a

financial institution to perform financial transactions, particularly cash withdrawal,


without the need for a human cashier, clerk or bank teller.

1. #include <iostream>
2.  
3. using namespace std;
4.  
5. int main()
6. {
7. float Balance = 100.00;
8. int account_type, option;
9. float amount;
10. //Option Menu for Account type selection
11. cout << "Welcome To ATM" << endl << endl;
12. cout << "1) Current" << endl;
13. cout << "2) Saving" << endl;
14. //Prompting user to select account type
15. cout << "Please select account type (1 or 2): ";
16. cin >> account_type;
17. //If user enters option 1 or 2
18. if(account_type == 1 || account_type == 2)
19. {
20. //Display account operations options to user
21. cout << "1) Withdraw Amount" << endl;
22. cout << "2) Balance Inquiry" << endl;
23. //prompt user to select operation
24. cout << "Select an option (1 or 2): ";
25. cin >> option;
26. if(option == 1) //User want to withdraw
27. {
28. //prompt user to enter amount he/she want to withdraw
29. cout << "Please enter amount to withdraw : ";
30. cin >> amount;
31. if(amount <= 0) // if amount entered is zero or negative
display error
32. {
33. cout << "Amount can not be zero or negative" << endl;
34. }
35. else if(amount > Balance) // if amount to withdraw is greater
than account balance, display error
36. {
37. cout << "You do not have much funds to withdraw this amount"
<< endl;
38. }
39. else // withdraw funds and display user success message
40. {
41. Balance = Balance - amount;
42. cout << "Balance withdrawl successful!!!. Your new balance is
" << Balance << endl;
43. }
44.
45. }
46. else if(option == 2) // if user select option 2, display account
balance
47. {
48. cout << "Your Balance is " << Balance << endl;
49. }
50. else
51. {
52. cout << "Invalid Option Selected." << endl;
53. }
54. }
55. else //wrong account type entered, display error message
56. {
57. cout << "Invalid Account type selected." << endl;
58. }
59. cout << "Thank You Using Our ATM!" << endl;
60. return 0;
61. }

Here is a simple project on ATM(Automated teller machine).The code is written in c++


language. Visual studio is used to compile the code. The code carry out all the functions
that all standard atm machines do. You can check amount present in your account,
withdraw balance and deposit amount. In the code below there are four ATM card
holders. Each card holder is assigned a pin code for their ATM cards and a password of
their account. The card holders with their names, Pin code of card’s and password of
account’s are listed below. 
         NAME                                  PINCODE                                PASSWORD

   ALI                              1111                                   5555


   SAJOO                       2222                                   6666
   IJAZ                            3333                                   7777
   TOUSEEF                  4444                                   8888

Atm code compilation and running


When you run the project compiled code in visual studio ide or its exe file. A text
message will pop up on the screen of the display “PLEASE ENTER THE PINCODE“.
Now enter the pin code assigned to four users above. Pin code must be of the person in
whose account you want to withdraw, deposit or print the balance receipt.
If the pin code is valid another message will be displayed on console  “ENTER
PASSWORD“. Enter the password of the person whose card pin code is previously
entered. Entering wrong password will give you an error message and the system will
ask you to please try again. If three times you entered a wrong password your card will
be captured (System just displays a message on console that your card is captured). 

Functions in c++ code


There are only two functions main() & printstar() in code. Main function is the core of
whole the atm system. Every thing is present in the main code. Printstar is just printing
*(Asterik). There is no big or complex logic in the code, only just use of simple if else
statements.
Whole of the atm logic is implemented in the if else statements. If you go through the
code you will find that all the users ALI, SAJOO, IJAZ and TOUSEEF are working on
the same logic and there is no difference in there codes.

As i mentioned earlier the project is simple. You can make it perfect by


introducing filing in it. Save the transactions of a person in a file, read the balance from
there, deposit balance there. By filing you can make a perfect ATM system system. This
code is just to give you an idea how to make atm machine.

So far the atm works on run time. Every record is lose when the application is closed. I
would suggest to attach the atm system with a database. So that each and every record
can be retrieved and assessed at later stages.

You might also like