How do I get my ATM Machine to accept PIN input only a total of 3 tries?
Here is my code
Code:
#include<stdio.h>
#include<conio.h>
int main(){
int balance = 15000;
int pin = 1016;
int pin2;
int newtransaction = 1; //new transaction , 2 end transaction
printf("***Welcome To Stehl's ATM Machine*** \n");
printf("Enter Pin: ");
scanf("%d", &pin2);
if(pin != pin2)
{
printf("Pin not Valid.");
return 0;
}
while(newtransaction == 1)
{
int option;
printf("Please pick an option \n");
printf("1 - Check your balance \n");
printf("2 - Deposit\n");
printf("3 - Withdraw\n");
scanf("%d" , &option );
if (option == 1)//balance
{
printf("Your current balance is : %d \n", balance);
}
else if (option == 2)//deposit
{
int deposit;
printf("Plese input deposit amount: ");
scanf("%d", &deposit);
if(deposit >0 )
{
balance += deposit;
printf("Your total balance is %d \n ", balance);
}
else
{
printf("Invalid amount\n");
}
}
else if (option == 3)//withdraw
{
int withdraw;
printf("Please input withdraw amount: ");
scanf("%d", &withdraw);
if(withdraw <= balance)
{
balance -= withdraw;
printf("Your total balance is %d \n", balance);
}
else {
if (withdraw > balance)
{
printf("Insufficient Balance. Declined \n");
}
}
}
else
{
printf("Invalid Transaction.\n");
}
newtransaction = 0;
while(newtransaction != 1 && newtransaction !=2)
{
printf("Do you want a new transaction?\n");
printf("1 - Yes\n");
printf("2 - No\n");
scanf("%d", &newtransaction);
}
}
getch();
return 0;
}