3 Replies - 979 Views - Last Post: 17 September 2011 - 05:06 AM Rate Topic: -----

#1 rdhc1330  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 130
  • Joined: 01-August 11

replace int PIN with asterisks

Posted 17 September 2011 - 12:18 AM

yo how's it going guys, I'm working on a little project of my own, going to be a pretty sweet piece of code when I'm done... what I want to know for now is, for my pinCode entry, how do I mask the number input and replace with asterisks? While keeping the functionality of == 5555 and !=5555?

here's my code:
#include <cstdlib>
#include <conio.h>
#include <iostream>
using namespace std;

void startMenu();
void newAccountMenu();
//------------------------------------------------------------------------------
int main(int argc, char *argv[])
{  
   int pinCode;
   int count = 2;
   
   cout << "Please enter your PIN code: ";
   cin >> pinCode; 
   
   do
   {
      if ( pinCode != 5555 && count > 0 )
      {
         system("cls");
         cout << "PIN incorrect, you have " << count << " more tries left: ";
         cin >> pinCode;
         count--;
      }
      
      if ( count == 0 )
      {
         system("cls");
         cout << "Sorry, you've got your PIN wrong too many times!" << endl
              << "Please see someone inside the bank.";
            break;
      }
   } while ( pinCode != 5555 );
   
   if ( pinCode == 5555 )
   {
      system("cls");
      cout << "Correct pin, fowarding you to bank menu, click to continue.";
         getch();
         
      system("cls");
      startMenu();
   }    
   
   getch();
   return 0;
}
//------------------------------------------------------------------------------
void startMenu()
{
   int choice;
   
   cout << "\t\t|--------------------------------------------------|" << endl
        << "\t\t|Welcome to Bank Syms, please enter your selection:|" << endl
        << "\t\t|--------------------------------------------------|" << endl
        << "\t\t| 1.   Register - New Customer                     |" << endl
        << "\t\t| 2.   Withdraw                                    |" << endl
        << "\t\t| 3.   Deposit                                     |" << endl
        << "\t\t| 4.   Balance                                     |" << endl
        << "\t\t| 5.   Exit                                        |" << endl
        << "\t\t|--------------------------------------------------|" << endl
        << "\t\t Selection: ";
        
   choice = getch();        
   while ( choice != 53 )
   { 
      switch ( choice )
      {
         case '1' :
            system("cls");
            newAccountMenu();
            getch();
            break;
      }
      
   }
}
//------------------------------------------------------------------------------
void newAccountMenu()
{  
   cout << "\t\t|--------------------------------------------------|" << endl
        << "\t\t|    Hello and welcome to the new account menu:    |" << endl
        << "\t\t|--------------------------------------------------|" << endl
        << "\t\t| 1.   Register checking account                   |" << endl
        << "\t\t| 2.   Register savings account                    |" << endl
        << "\t\t| 3.   Register checking and savings account       |" << endl
        << "\t\t| 4.   Return to top menu                          |" << endl
        << "\t\t|--------------------------------------------------|" << endl
        << "\t\t  Selection: ";   
}  
//------------------------------------------------------------------------------       



Cheers in advance...!

Is This A Good Question/Topic? 1
  • +

Replies To: replace int PIN with asterisks

#2 hulla  Icon User is offline

  • Writing Lines


Reputation: 49
  • View blog
  • Posts: 732
  • Joined: 05-March 11

Re: replace int PIN with asterisks

Posted 17 September 2011 - 02:36 AM

Quote

yo how's it going guys

Great. :) What about yourself?

I changed your code so that it has a new function: authentication().

#include <cstdlib>
#include <conio.h>
#include <iostream>
using namespace std;

bool authentication();
void startMenu();
void newAccountMenu();
//------------------------------------------------------------------------------
int main(int argc, char *argv[])
{
   int pinCode;
   int count = 2;

   cout << "Please enter your PIN code: ";
   bool auth = authentication();

   do
   {
      if ( !auth && count > 0 )
      {
         system("cls");
         cout << "PIN incorrect, you have " << count << " more tries left: ";
         auth = authentication();
         count--;
      }

      if ( count == 0 )
      {
         system("cls");
         cout << "Sorry, you've got your PIN wrong too many times!" << endl
              << "Please see someone inside the bank.";
            break;
      }
   } while ( !auth );

   if ( auth )
   {
      system("cls");
      cout << "Correct PIN, fowarding you to bank menu, click to continue.";
         getch();

      system("cls");
      startMenu();
   }

   getch();
   return 0;
}
//------------------------------------------------------------------------------
void startMenu()
{
   int choice;

   cout << "\t\t|--------------------------------------------------|" << endl
        << "\t\t|Welcome to Bank Syms, please enter your selection:|" << endl
        << "\t\t|--------------------------------------------------|" << endl
        << "\t\t| 1.   Register - New Customer                     |" << endl
        << "\t\t| 2.   Withdraw                                    |" << endl
        << "\t\t| 3.   Deposit                                     |" << endl
        << "\t\t| 4.   Balance                                     |" << endl
        << "\t\t| 5.   Exit                                        |" << endl
        << "\t\t|--------------------------------------------------|" << endl
        << "\t\t Selection: ";

   choice = getch();
   while ( choice != 53 )
   {
      switch ( choice )
      {
         case '1' :
            system("cls");
            newAccountMenu();
            getch();
            break;
      }

   }
}
//------------------------------------------------------------------------------
void newAccountMenu()
{
   cout << "\t\t|--------------------------------------------------|" << endl
        << "\t\t|    Hello and welcome to the new account menu:    |" << endl
        << "\t\t|--------------------------------------------------|" << endl
        << "\t\t| 1.   Register checking account                   |" << endl
        << "\t\t| 2.   Register savings account                    |" << endl
        << "\t\t| 3.   Register checking and savings account       |" << endl
        << "\t\t| 4.   Return to top menu                          |" << endl
        << "\t\t|--------------------------------------------------|" << endl
        << "\t\t  Selection: ";
}
//------------------------------------------------------------------------------
bool authentication()
{
    bool authenticate[5] = {false, false, false, false, true};
    int iii = 0;
    for(; ; iii++)
    {
        char ch = getch();
        if(ch == 13) break; // If the user pressed \"Enter\" (13 in ASCII), break
        cout << "*";
        // If the 1st to 4th _getch is 5, assign element iii of authenticate with true
        if     (ch == '5' && iii <= 3) authenticate[iii] = true;
        else if(iii == 4)              authenticate[4] = false;
    }
    if(authenticate[0] &&
       authenticate[1] &&
       authenticate[2] &&
       authenticate[3] &&
       authenticate[4])     { return true; }
    else return false;
}



Hope this helps . . .
Was This Post Helpful? 1
  • +
  • -

#3 rdhc1330  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 130
  • Joined: 01-August 11

Re: replace int PIN with asterisks

Posted 17 September 2011 - 02:40 AM

hulla, on 17 September 2011 - 02:36 AM, said:

Very much so, thank you... I'm going to implicate it now. Any more problems and I'll be back


Very much so, thank you... I'm going to implicate it now. Any more problems and I'll be back :)

This post has been edited by rdhc1330: 17 September 2011 - 03:28 PM

Was This Post Helpful? 0
  • +
  • -

#4 rdhc1330  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 130
  • Joined: 01-August 11

Re: replace int PIN with asterisks

Posted 17 September 2011 - 05:06 AM

So I've done this much so far:

#include <cstdlib>
#include <conio.h>
#include <iostream>
using namespace std;

bool authentication();
void startMenu();
void newAccountMenu();
void withdrawMenu();
//------------------------------------------------------------------------------
int main(int argc, char *argv[])
{  
   int pinCode;
   int count = 2;
   srand ( time ( 0 ) );
   
   cout << "Please enter your PIN code: ";
   bool auth = authentication();
   
   do
   {
      if ( !auth && count > 0 )
      {
         system("cls");
         cout << "PIN incorrect, you have " << count << " more tries left: ";
         auth = authentication();
         count--;
      }
      
      if ( count == 0 )
      {
         system("cls");
         cout << "Sorry, you've got your PIN wrong too many times!" << endl
              << "Please see someone inside the bank.";
            break;
      }
   } while ( !auth );
   
   if ( auth )
   {
      system("cls");
      cout << "Correct pin, fowarding you to bank menu, click to continue.";
         getch();
         
      system("cls");
      startMenu();
   }    
   
   getch();
   return 0;
}
//------------------------------------------------------------------------------
void startMenu()
{
   int choice;
   
   cout << "\t\t|--------------------------------------------------|" << endl
        << "\t\t|Welcome to Bank Syms, please enter your selection:|" << endl
        << "\t\t|--------------------------------------------------|" << endl
        << "\t\t| 1.   Register - New Customer                     |" << endl
        << "\t\t| 2.   Withdraw                                    |" << endl
        << "\t\t| 3.   Deposit                                     |" << endl
        << "\t\t| 4.   Balance                                     |" << endl
        << "\t\t| 5.   Exit                                        |" << endl
        << "\t\t|--------------------------------------------------|" << endl
        << "\t\t Selection: ";
        
   choice = getch();        
   while ( choice != 53 && choice > 1 || choice < 5 )
   { 
      switch ( choice )
      {
         case '1' :
            system("cls");
            newAccountMenu();
            getch();
               break;
         
         case '2' :
            system("cls");
            withdrawMenu();
            getch();
               break;
      }
      
   }
}
//------------------------------------------------------------------------------
void newAccountMenu()
{ 
   int choice;
   int acctNum1 [ 16 ];
   int acctNum2 [ 16 ];
   char first [ 12 ];
   char last [ 12 ]; 
   float chqBal;
   float savBal; 
   
   cout << "\t\t|--------------------------------------------------|" << endl
        << "\t\t|    Hello and welcome to the new account menu:    |" << endl
        << "\t\t|--------------------------------------------------|" << endl
        << "\t\t| 1.   Register checking account                   |" << endl
        << "\t\t| 2.   Register savings account                    |" << endl
        << "\t\t| 3.   Register checking and savings account       |" << endl
        << "\t\t| 4.   Return to top menu                          |" << endl
        << "\t\t|--------------------------------------------------|" << endl
        << "\t\t  Selection: "; 
        
        choice = getch();        
   while ( choice != 53 )
   { 
      switch ( choice )
      {
         case '1' :
            system("cls");
            cout << "\t\tNew Checking Account! Welcome. " << endl << endl;
            cout << "  Please enter your first name: ";
            cin >> first;
            cout << "  Please enter your last name: "; 
            cin >> last;
            cout << endl << "  Why hello " << first << " " << last 
            << "!" << endl;
           
            for ( int i = 0; i < 15; i++ )
            {
               acctNum1 [ i ] = ( rand ( ) % 10 );
            }
            cout << "  Here is your new account number: ";
            cout << acctNum1 [ 1 ] << acctNum1 [ 2 ] << " " << acctNum1 [ 3 ]
                 << acctNum1 [ 4 ] << acctNum1 [ 5 ] << acctNum1 [ 6 ] << " " 
                 << acctNum1 [ 7 ] << acctNum1 [ 8 ] << acctNum1 [ 9 ]
                 << acctNum1 [ 10 ] << acctNum1 [ 11 ] << acctNum1 [ 12 ]
                 << acctNum1 [ 13 ] << " " << acctNum1 [ 14 ] << acctNum1 [ 15 ]
                 << endl << endl;
            
            cout << "  How much would you like to deposit to start? " << endl
                 << "  Seperate Dollars and Cents with a full stop! " << endl
                 << "  $";
            cin >> chqBal;
            
            cout << endl << "  Excellent! Your checking account now contains $"
                 << chqBal << endl << "  Click to return to the top menu.";
                 
            getch();
            system("cls");     
            startMenu();
               break;
         
         case '2' :
            system("cls");
            cout << "\t\tNew Savings Account! Welcome. " << endl << endl;
            cout << "  Please enter your first name: ";
            cin >> first;
            cout << "  Please enter your last name: "; 
            cin >> last;
            cout << endl << "  Why hello " << first << " " << last 
            << "!" << endl;
           
            for ( int i = 0; i < 15; i++ )
            {
               acctNum2 [ i ] = ( rand ( ) % 10 );
            }
            cout << "  Here is your new account number: ";
            cout << acctNum2 [ 1 ] << acctNum2 [ 2 ] << " " << acctNum2 [ 3 ]
                 << acctNum2 [ 4 ] << acctNum2 [ 5 ] << acctNum2 [ 6 ] << " " 
                 << acctNum2 [ 7 ] << acctNum2 [ 8 ] << acctNum2 [ 9 ]
                 << acctNum2 [ 10 ] << acctNum2 [ 11 ] << acctNum2 [ 12 ]
                 << acctNum2 [ 13 ] << " " << acctNum2 [ 14 ] << acctNum2 [ 15 ]
                 << endl << endl;
            
            cout << "  How much would you like to deposit to start? " << endl
                 << "  Seperate Dollars and Cents with a full stop! " << endl
                 << "  $";
            cin >> savBal;
            
            cout << endl << "  Excellent! Your savings account now contains $"
                 << savBal << endl << "  Click to return to the top menu.";
                 
            getch();
            system("cls");     
            startMenu();
               break;
            
         case '3' :
            system("cls");
            cout << "\t\tNew Savings & Checking Accounts! Welcome. " 
                 << endl << endl;
            cout << "  Please enter your first name: ";
            cin >> first;
            cout << "  Please enter your last name: "; 
            cin >> last;
            cout << endl << "  Why hello " << first << " " << last 
            << "!" << endl << endl;
            
            for ( int i = 0; i < 15; i++ )
            {
               acctNum1 [ i ] = ( rand ( ) % 10 );
            }
            cout << "  Here is your new checking account number: ";
            cout << acctNum1 [ 1 ] << acctNum1 [ 2 ] << " " << acctNum1 [ 3 ]
                 << acctNum1 [ 4 ] << acctNum1 [ 5 ] << acctNum1 [ 6 ] << " " 
                 << acctNum1 [ 7 ] << acctNum1 [ 8 ] << acctNum1 [ 9 ]
                 << acctNum1 [ 10 ] << acctNum1 [ 11 ] << acctNum1 [ 12 ]
                 << acctNum1 [ 13 ] << " " << acctNum1 [ 14 ] << acctNum1 [ 15 ]
                 << endl << endl;
                 
            cout << "  How much would you like to deposit into your checking"
                 << "  account?" << endl
                 << "  Seperate Dollars and Cents with a full stop! " << endl
                 << "  $";
            cin >> chqBal;
           
            for ( int i = 0; i < 15; i++ )
            {
               acctNum2 [ i ] = ( rand ( ) % 10 );
            }
            cout << endl << "  Here is your new savings account number: ";
            cout << acctNum2 [ 1 ] << acctNum2 [ 2 ] << " " << acctNum2 [ 3 ]
                 << acctNum2 [ 4 ] << acctNum2 [ 5 ] << acctNum2 [ 6 ] << " " 
                 << acctNum2 [ 7 ] << acctNum2 [ 8 ] << acctNum2 [ 9 ]
                 << acctNum2 [ 10 ] << acctNum2 [ 11 ] << acctNum2 [ 12 ]
                 << acctNum2 [ 13 ] << " " << acctNum2 [ 14 ] << acctNum2 [ 15 ]
                 << endl << endl;
            
            cout << "  And your savings account? " << endl
                 << "  $";
            cin >> savBal;
            
            cout << endl << "  Excellent! Your savings account now contains $"
                 << savBal << endl << "  and your checking account now contains" 
                 << " $" << chqBal << endl 
                 << "  Click to return to the top menu.";
                 
            getch();
            system("cls");     
            startMenu();
               break; 
            
         case '4' : 
            system("cls");
            startMenu(); 
      }
   }  
}  
//------------------------------------------------------------------------------
void withdrawMenu()
{
      
}
//------------------------------------------------------------------------------       
bool authentication()
{
    bool authenticate[ 5 ] = { false, false, false, false, true };
    int i = 0;
    for( ; ; i++ )
    {
        char ch = getch();
        if( ch == 13 )
           break; 
        cout << "*";
        
        if ( ch == '5' && i <= 3 ) authenticate [ i ] = true;
        else if( i == 4 )          authenticate[ 4 ] = false;
    }
    if ( authenticate[ 0 ] &&
         authenticate[ 1 ] &&
         authenticate[ 2 ] &&
         authenticate[ 3 ] &&
         authenticate[ 4 ] )    
         
    { return true; }
    else return false;
}
//------------------------------------------------------------------------------



Just wondering how I can take the balance values from void newAccountMenu() and use them for the rest of the program. Say withdrawMenu(), if it could come up with the account holder name, account number and balances etc?
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1