My program is a ATM C++ program. I am using gedit in ubuntu to create the program.
I have a txt file with pin,cardNumber,balance. The data is all numbers
seperated by commas.(5644,23454443434555543,230.44) I would like to be able to create an array of some sort
At the present time I am just entering a card number that has
no value, i am using a variable for Pin and assigning it
a pin value but need to get away from doing it this way.
I would like to be able to get the user to enter a card number
so that the program would search to locate the correct card number
from the txt file and then store the pin and balance so that i
can update the balance with user input.
After the program has validated the correct card number I would be
able to carry on and do some transactions.
I have a few other issues that I would like some help with please.
1: when cash withdraw is first selected , the program ends due to no funds.
I would like to be able to go back to the main menu instead of crashing.
2:On deposit when you have selected an amount it ask if you would like another transaction,
when you press 1 for yes it ends the program.
3: On balance Inquiry when it ask if you would like another transaction,
when you press 1 for yes it ends the program.
I am not the best programmer and I know there are a lot better ways of doing
this program but I have come a long way in a few months and I am trying hard to get to grips with each ellement.
Can some one please help.
Many thanks.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179
|
#include <iostream>
#include <cstdlib>
#include <string>
#include <fstream>
#include <vector>
#include <functional>
#include <stdlib.h>
using namespace std;
double balance = 0, current_amount;
int option;
int another_transaction = 1;
long cardNumber;
bool cardFound = true;
bool pinOk = true;
int pin = teddy;
int tries = 1;
int main(void) {
cout << "\n\n"<<endl;
cout << " **************************************\n";
cout << " **************************************\n";
cout << " **************************************\n";
cout << " ***** WELCOME TO MAINLAND`S BANK:*****\n";
cout << " **************************************\n";
cout << " **************************************\n";
cout << " **************************************\n";
cout << "\n\n"<<endl;
void();
{
string pin;
int x = 1;
cout << " Please enter the long card number :";
cin >>cardNumber;
if(!cardNumber)
{
cout << " Error Reading card: "<<endl;
++cardNumber;
}
else{
cout << " Card details excepted\n";
cout << " **************************************\n";
}
while (1) //This creates an overall top level infinite loop
{
cout << " Input pin here: ";
cin >> pin;
if ( pin == "teddy") //This sets the condition for success
{
cout << " Access Granted!!!!\n";
break; //The break is applied here to stop the cycle after success is made
}
else if ( pin != "teddy") //This sets the condition for failure
{
cout << " Incorrect Pin!!! " << "\n" " You have made "<< x << " " << "wrong attempts" << "\n";
++x;
if ( x > 3 ) // This is the counter limit portion. Limit set to 5 attempts
{
cout << " You have exceeded the amount of tries and your account is frozen" <<endl;
cout << " Please Contact your local branch" <<endl;
return 0;
}
}
}
}
//exit main if pin wrong}
while(another_transaction == 1){
cout<<" Login Successful"<<endl;
cout<< " **************************************\n";
cout<< "\n";
cout<<" Main Menu: "<<endl;
cout<< "----------------------\n";
cout<<" 1. Cash Withdraw:"<<endl;
cout<<" 2. Cash Deposit: "<<endl;
cout<<" 3. Balance Inquiry "<<endl;
cout<<" 4. Exit: "<<endl;
cin>>option;
if(option == 1)
{
cout<<" The balance in your account is £"<<balance<<endl;
if(balance <= 0)
{
cout<<" Your account is empty. \n Please make a deposit:"<<endl;
return 0; // exit option if balance <0
}
cout<<" How much do you want to withdraw? "<<endl;
cout<<" Amount: £";
cin>>current_amount;
cout<<"\n You are about to withdraw £"<< current_amount <<endl;
cout<<" Is this correct"<<endl;
cout<<" 1 - YES "<<endl;
cout<<" 2 - NO "<<endl;
cin>>another_transaction;
if(current_amount < balance){
balance = balance - current_amount ;
cout<<" Withdraw Successful £"<<current_amount<<endl;
cout<<" Your new Balance is £"<<balance;
cout<<endl<<endl;
// let them withdraw amount
} else {
cout<<" You do not have enough funds in your account "<<endl<<endl;
}
} else if(option == 2){
cout<<" Enter deposit amount £";
cin>>current_amount;
balance = current_amount + balance ;
cout<<"\n You are about to Deposit £"<< current_amount <<endl;
cout<<" Is this correct?"<<endl;
cout<<" 1 - YES "<<endl;
cout<<" 2 - NO "<<endl;
cin>>another_transaction;
cout<<" You have deposited £"<<current_amount<<endl;
cout<<" Your new balance is £"<<balance<<endl<<endl;
} else if (option == 3){
cout<<" Your balance is £"<<balance;
cout<<endl<<endl;
} else if (option == 4){
cout<<"_____________________________\n";
cout<<" Thank You for your custom \n";
cout<<" PLease come back again soon\n ";
cout<<"_____________________________\n";
return 0 ;
} else {
cout<<" You enterd invalid choice "<<endl<<endl<<endl;
}
another_transaction = 0;
while(another_transaction !=1 && another_transaction !=2){
cout<<"\n Would you like another transaction? \n\n"<<endl;
cout<<" 1 - YES "<<endl;
cout<<" 2 - NO "<<endl;
cin>>another_transaction;
cout<<" Thank you and good bye "<<endl;
cout<<"\n"<<endl;
}
return 0; //end of main if option is to exit
}}
|