my problem here is INQUIRY and WITHDRAW.. what should i do? cn u pls help me?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • carmela
    New Member
    • Mar 2014
    • 1

    my problem here is INQUIRY and WITHDRAW.. what should i do? cn u pls help me?

    Code:
    #include <iostream>
    #include <conio.h>
    #include <windows.h>
    
    void newAccount();
    void Inquiry();
    void Deposit();
    void Withdraw();
    void List();
    int exitProgram();
    void menu();
    using namespace std;
    string name[10];
    int accountID[10], newAccountID;
    int pin[10], newPIN;
    double balance[10];
    double amountDeposited=0.0;
    int counter =0;
    int main(){
        system ("cls");
        menu();
        getch();
        return 0;
    }
    
    void menu(){
         char answer;
         system("cls");
         cout<<"\t\tWelcome to World Bank, Insert your Card in ATMmachine\n";
         cout<<"\n";
         cout<<"\t\t\tHello,Please enter your user name:\t\n";
         cout<<"\n";
         cout<<"[N]*New Account \n";
         cout<<"[D]*Deposit \n";
         cout<<"[I]*Inquiry \n";
         cout<<"[W]*Withdraw \n";
         cout<<"[L]*List all accounts\n";
         cout<<"[E]*Exit Program \n";
         cout<<"\nPlease Select : ";
         cin>> answer;
         if (answer == 'n' || answer == 'N'){
            newAccount();
         }else if (answer == 'd' || answer == 'D'){
            Deposit();
         }else if (answer == 'I' || answer == 'i'){
            Inquiry();
         }else if (answer == 'w' || answer == 'W'){
            Withdraw();
         }else if (answer == 'e' || answer == 'E'){
            exitProgram();
             }else if (answer == 'l' || answer == 'L'){
            List();
         }else{
            cout <<"Invalid";
         }     
    }
    
    void newAccount(){
         system ("cls");
         cout<<"\nAccount ID      : ";
         cin>>accountID[counter]; 
         cout<<"PIN             : ";
         cin>>pin[counter];
         cout<<"Initial Deposit : ";
         cin>>amountDeposited;
         balance[counter] = balance[counter] + amountDeposited;
         counter++;
         menu();
    }
    
    void Deposit(){
         system("cls");
         cout<<"\nAccount ID      : ";
         cin>>newAccountID;
         for (int y=0; y<counter; y++){
             if (newAccountID == accountID[y]){
                cout<<"PIN             : ";
                cin>>newPIN;
                if (newPIN == pin[y]){
                    cout<<"How much to be deposited ? ";
                    cin>>amountDeposited;
                    balance[y] = balance[y] + amountDeposited;
                    cout<<"Your current balance is : "<<balance[y];
                    cout<<"\n Press any key to continue...";
                    getch();
                }else{
                    cout <<"Invalid\n";
                    getch();  
                    Deposit();  
                }      
             }
             
         }
         menu();
    }
    
    void Inquiry(){
         system("cls");
         cout<<"\nAccount ID      : ";
         cin>>newAccountID;
         cout<<"PIN             : ";
         cin>>newPIN;
         if (newAccountID == accountID[counter] && pin[counter] == newPIN){
            cout<<"Your current balance is : " << balance;  
         }else{
              cout<<"Invalid account, Press Enter to continue \n"; 
              getch();
              Inquiry();
         }
         
         getch();
         menu();
    }
    
    void Withdraw(){
         system("cls");
         int amount;
         cout<<"Account ID  :";
         cin >>newAccountID;
         cout<<"PIN         :";
         cin>>newPIN;
         if (newAccountID == accountID[counter] && pin[counter] == newPIN){
            cout<<"Enter Amount   :";
            cin >>amount;
            if (amount > balance[counter]){
               cout<<"Insuficient Balance \n";
               cout<<"Please enter a valid amount";
               getch();
               Withdraw();
            }else{
                cout<<"Processing....\n\n";
                balance[counter] = balance[counter] - amount;
                cout<<"Press Enter to continue";
            }
         }else{
              cout << "Invalid account, Press Enter to continue \n"; 
              getch();
              Withdraw();
         }
         
         getch();
         menu();
         
    }
    void List(){
           system("cls");
           cout<<"AccountID\t"<<"PIN"<<"\t"<<"Balance"<<"\n";
           for (int x=0; x<counter; x++){
             cout << accountID[x]<< "\t"<<"\t";
             cout << pin[x]<<"\t";
             cout << balance[x];
             cout << "\n";
             
         }
         getch();
         menu();
    }
    
    int exitProgram(){
         cout << "\n\n \t\t thankyooooou! :) ";
         return 0;
    }
    Last edited by Rabbit; Mar 3 '14, 06:15 AM. Reason: Please use [CODE] and [/CODE] tags when posting code or formatted data.
  • weaknessforcats
    Recognized Expert Expert
    • Mar 2007
    • 9214

    #2
    What is your problem exactly?

    Comment

    • donbock
      Recognized Expert Top Contributor
      • Mar 2008
      • 2427

      #3
      I notice that Deposit(), Inquiry(), and Withdraw() are recursive; and the recursion is potentially unbounded. I think you want to loop back to near the start of these functions (rather than invoke another instance) when faced with invalid input.

      Comment

      Working...