Having problem in pin code if the user will input less than 4 digit number and a character type..could some1 help me from this.. (@@,

#include<stdio.h>
#include<conio.h>
#include<iostream.h>

float choice2();
float choice3();

float ball[11]={1000,1000,1000,1000,1000,1000,1000,1000,1000,1000,1000};
float mypin;

float withdraw, deposit;
int transaction, myaccount;
char transaction1;

main()
{           
    pin:{     
              system("cls");
              printf("Enter pin code: ");  
              scanf("%f",&mypin);

             }                   
            if (mypin==1234)
            { 
            myaccount=0;
            }
            else if(mypin==2345)
            {
            myaccount=1;
            } 
            else if(mypin==3456)
            {
            myaccount=2;
            }
            else if(mypin==4567)
            {
            myaccount=3;
            }
            else if(mypin==5678)
            {
            myaccount=4;
            }
            else if(mypin==6789)
            {
            myaccount=5;
            }
            else if(mypin==7890) 
            {
            myaccount=6;
            }
            else if(mypin==8901)
            {
            myaccount=7;
            }
            else if(mypin==9012)
            {
            myaccount=8;
            }
            else if(mypin==0123)
            {
            myaccount=9;
            }
            else if(mypin==2234)
            {
             myaccount=10;
             }
            else if(mypin==2245)
            {
            myaccount=9;
            }
            else if(mypin==2256)
            {
            myaccount=10;
            }
            else if(mypin==2267)
            {
            myaccount=11;
            } 
             else{
                  goto pin;
                  }

            if(mypin!=1234 && mypin!=2345 && mypin!=3456 && mypin!=4567 && mypin!=5678 && mypin!=6789 && mypin!=7890 && mypin!=8901 && mypin!=0123 && mypin!=2234 && mypin!=2245 && mypin!=2256 && mypin!=2267){
}
                    menu:{
                    printf("\n\t\t\tTRANSACTION\n");
                    printf("\n\t\tChoose your transaction: \n");
                    printf("\n\t\t[1]: Balance Inquiry");
                    printf("\n\t\t[2]: Withdraw");
                    printf("\n\t\t[3]: Deposit");
                    printf("\n\t\t[4]: Exit Transaction\n\n");  
                    printf("Your transaction: ");
                    scanf("%d",&transaction);  


}               

  if(transaction==1){
                               printf("\n \t\tBalance Inquiry \n\n");
                               printf("\tYour Available balance : %0.2f",ball[myaccount]);

                               printf("\n\n Do you want another transaction[y][n]: ");
                               scanf("%s", &transaction1);   

  if(transaction1=='y' || transaction=='Y'){
                                        goto menu;
                                                             }
                     else if(transaction1=='n' || transaction1=='N'){
                                    printf("Do you want to another account[y][n]");
                                    scanf("%s", &transaction1);
                     if(transaction1=='y' || transaction=='Y'){
                                                       main(); }
                     else if(transaction1=='n' || transaction1=='N'){
                                          return 0;}

                                                                   }
     }//end sa trans1
  else if(transaction==2){
                               printf("\n \t\tWithdraw \n\n");
                               choice2();

                               printf("\n\n Do you want another transaction[y][n]: ");
                               scanf("%s", &transaction1);   
                   if(transaction1=='y' || transaction=='Y'){
                                        goto menu;
                                                             }
                     else if(transaction1=='n' || transaction1=='N'){
                                    printf("Do you want to another account[y][n]");
                                    scanf("%s", &transaction1);
                   if(transaction1=='y' || transaction=='Y'){
                                        main(); }
                                        else if(transaction1=='n' || transaction1=='N'){
                                             return 0;}
}
                            }          
  else if(transaction==3){
                               printf("\n \t\tDeposit \n\n");
                               choice3();        

                               printf("\n\n Do you want another transaction[y][n]: ");
                               scanf("%s", &transaction1);   
                   if(transaction1=='y' || transaction=='Y'){
                                        goto menu;
                                                             }
                     else if(transaction1=='n' || transaction1=='N'){
                                    printf("Do you want to another account[y][n]");
                                    scanf("%s", &transaction1);
                   if(transaction1=='y' || transaction=='Y'){
                                        main(); }
                                        else if(transaction1=='n' || transaction1=='N'){
                                             return 0;}                       
}
                                  }
  else if(transaction==4){
                               printf("\n \t\tExit \n\n");
                               printf("\t\t\tDo you want to another account[y][n]");
                               scanf("%s", &transaction1);
                   if(transaction1=='y' || transaction=='Y'){
                                        main(); }
                                        else if(transaction1=='n' || transaction1=='N'){
                                             return 0;}   


}              
getch();
return 0;
}
float choice2()
{                  
       printf("\n\tHow much do you want to withdraw?: ");
       scanf("%f", &withdraw);
     if(withdraw>ball[myaccount]){
       printf("\n\nInsuficient Balance\n");
       printf("You have only %0.2f in your account", ball[myaccount]);              
       getch ();                                                      
       }
     else if(ball[myaccount]>withdraw){                           
       printf("\n\tYou withdraw: %0.2f pesos", withdraw);
       printf("\n\tYour current balance: %0.2f pesos", ball[myaccount]-withdraw);
       ball[myaccount]=ball[myaccount]-withdraw;
                                }
}
float choice3()
{
                printf("\n\tHow much do you want to deposit?: ");
                scanf("%f", &deposit);
                printf("\n\tYou deposited %0.2f pesos", deposit);
                printf("\n\tYour current balance: %0.2f pesos", deposit+ball[myaccount]);           
                ball[myaccount]=deposit+ball[myaccount];
}

to validate the PIN you could try this:

string mypin = "";
int myaccount = -1;
int main()
{
    while(myaccount == -1)
    {
        system("cls");
        printf("Enter PIN code: ");
        scanf("%f",&mypin);
        switch(mypin)
        {            
            case "1234" :
                myaccount=0;
                break;
            case "2345" :
                myaccount=1;           
                break;
            case "3456" :
                myaccount=2;            
                break;
            case "4567" :
                myaccount=3;            
                break;            
            case "5678" :
                myaccount=4;           
                break;
            case "6789" :
                myaccount=5;            
                break;
            case "7890" :
                myaccount=6;
                goodpin=true;            
                break;
            case "8901" :
                myaccount=7;           
                break;
            case "9012" :
                myaccount=8;
                goodpin=true;            
                break;
            case "0123" :
                myaccount=9;           
                break;
            case "2234" :
                myaccount=10;           
                break;
            case "2245" :
                myaccount=9;            
                break;
            case "2256" :
                myaccount=10;
                goodpin=true;            
                break;
            case "2267" :
                myaccount=11;            
                break;
            default:
                printf("Wrong PIN please re-enter");
                mypin = "";
        }
    }

Anything that isn't a valid pin will get rejected. You shouldn't need to test for valid pin in the rest of your code just use the value of myaccount.

I switched mypin to a string since, with int, 0123 = 123.

oops half asleep still, can't use strings in a switch block. try changing the input type to string

#include<iostream>
using namespace std;
string mypin;
int myaccount = -1;
int main()
{
    while(myaccount == -1)
    {
        //system("cls");
        printf("Enter PIN code: ");
        cin >> mypin;

        if (mypin=="1234")
        {
            myaccount=0;
        }
        else if(mypin=="2345")
        {
            myaccount=1;
        }
        else if(mypin=="3456")
        {
            myaccount=2;
        }
        else if(mypin=="4567")
        {
            myaccount=3;
        }
        else if(mypin=="5678")
        {
            myaccount=4;
        }
        else if(mypin=="6789")
        {
            myaccount=5;
        }
        else if(mypin=="7890")
        {
            myaccount=6;
        }
        else if(mypin=="8901")
        {
            myaccount=7;
        }
        else if(mypin=="9012")
        {
            myaccount=8;
        }
        else if(mypin=="0123")
        {
            myaccount=9;
        }
        else if(mypin=="2234")
        {
            myaccount=10;
        }
        else if(mypin=="2245")
        {
            myaccount=9;
        }
        else if(mypin=="2256")
        {
            myaccount=10;
        }
        else if(mypin=="2267")
        {
            myaccount=11;
        }
        else
            cout << "Wrong PIN please re-enter" << mypin;
    }
return 0;
}

Thank you so much..pretty great help.. :)

How about when withdrawing and depositing it just only accept whole amount and not exist ..

yah it's a great help... :D thanks..

If your problem is solved please mark this as solved. thanks

Last question about whole number at it said by phoenx ..
Withdrawing and Depositing amount in whole number in an ATM..

example withdrawing 100 if the user inputed 95, 96 etc.it won't allow to withdraw..

Here's some code you might find useful. Re-worked it so that main is less cluttered, and also 'conio.h' is not needed. I changed withdraw to accept only multiples of 100.

#include<stdio.h>
#include<iostream>
#include<cmath>
using namespace std;

float ball[11]= {1000,1000,1000,1000,1000,1000,1000,1000,1000,1000,1000};
float withdraw, deposit;
int transaction = -1;
int myaccount = -1;
void ClearScr()
{
    cout << "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n";
}
void Continue()
{
    cin.ignore();
    cin.get();
}
void Continue(string message)
{
    cout << message << "\n";
    cin.ignore();
    cin.get();
}
void CurrentBalance()
{
    printf("\n\tYour current balance: %0.2f pesos\n", ball[myaccount]);
    Continue("Press Enter to continue");
}
int NewAcct()
{
    string mypin = "";
    int myaccount = -1;
    while(myaccount == -1)
    {
        printf("Enter PIN code: ");
        cin >> mypin;
        if (mypin=="1234")
            myaccount=0;
        else if(mypin=="2345")
            myaccount=1;
        else if(mypin=="3456")
            myaccount=2;
        else if(mypin=="4567")
            myaccount=3;
        else if(mypin=="5678")
            myaccount=4;
        else if(mypin=="6789")
            myaccount=5;
        else if(mypin=="7890")
            myaccount=6;
        else if(mypin=="8901")
            myaccount=7;
        else if(mypin=="9012")
            myaccount=8;
        else if(mypin=="0123")
            myaccount=9;
        else if(mypin=="2234")
            myaccount=10;
        else if(mypin=="2245")
            myaccount=9;
        else if(mypin=="2256")
            myaccount=10;
        else if(mypin=="2267")
            myaccount=11;
        else
            cout << "Wrong PIN("  << mypin <<") please re-enter\n";
    }
    ClearScr();
    return myaccount;
}
void Withdraw()
{
    bool done = false;
    while(!done)
    {

        printf("\n\tHow much do you want to withdraw?: ");
        scanf("%f", &withdraw);
        if(fmod(withdraw, 100) == 0)
        {

            if(withdraw>ball[myaccount])
            {
                printf("\n\nInsuficient Balance\n");
                printf("You have only %0.2f in your account", ball[myaccount]);
                Continue();
            }
            else
            {
                ball[myaccount]=ball[myaccount]-withdraw;
                printf("\n\tYou withdrew: %0.2f pesos", withdraw);
                CurrentBalance();
                done = true;
            }

        }
        else
            cout << "Withdrawal amount must be a multiple of 20.\n";
    }
    Continue("Press Enter to continue");
}

void Deposit()
{
    printf("\n\tHow much do you want to deposit?: ");
    scanf("%f", &deposit);
    ball[myaccount]=deposit+ball[myaccount];
    printf("\n\tYou deposited %0.2f pesos", deposit);
    CurrentBalance();
}
void MainMenu()
{
    printf("\n\t\t\tTRANSACTION\n");
    printf("\n\t\tChoose your transaction: \n");
    printf("\n\t\t[1]: Balance Inquiry");
    printf("\n\t\t[2]: Withdraw");
    printf("\n\t\t[3]: Deposit");
    printf("\n\t\t[4]: Change Account");
    printf("\n\t\t[0]: Exit Transaction\n\n");
    printf("Your transaction: ");
    scanf("%d",&transaction);
}
int main()
{
    while(transaction != 0)
    {
        if (myaccount == -1)
            myaccount = NewAcct();
        MainMenu();
        switch (transaction)
        {
        case 1:
            printf("\n \t\tBalance Inquiry \n\n");
            CurrentBalance();
            ClearScr();
            break;
        case 2:
            Withdraw();
            break;
        case 3:
            Deposit();
            break;
        case 4:
            myaccount = -1;
            ClearScr();
            break;
        case 0:
            cout << "Goodbye, press enter to exit";
            break;
        default:
            cout << "Please enter a valid choice:\n";
        }
        ClearScr();
    }
    Continue("Press Enter to exit");
    return 0;
}

Thanks again.. :)

what is the used of floating ball[11]?and also using namespace std;?

How about including Change PIN in a transaction ?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.