signing 'if statements' to 'arrays'

This is a discussion on signing 'if statements' to 'arrays' within the C++ Programming forums, part of the General Programming Boards category; Does anyone know a better way to sign an if statement to an array? Check out this example: PHP Code: ...

  1. #1
    Registered User Machewy's Avatar
    Join Date
    Apr 2003
    Posts
    42

    Question signing 'if statements' to 'arrays'

    Does anyone know a better way to sign an if statement to an array?
    Check out this example:






    PHP Code:
    #include <iostream.h>
    #include <stdlib.h>
    #include <string.h>

    int main()
    {

          
    char szopenftp[20];
          
    char szeditftp[20];
          
    char szadminftp[20];
          
    char szpassftp[20];

          
    cout<<" ---------------------------------------- "<<endl;
          
    cout<<" Welcome to 'Cracker Trainer' version 1.0 "<<endl;
          
    cout<<" ---------------------------------------- "<<endl;
          
    cout<<endl;
          
    cout<<" This program is to simulate the ftp on a computer. "<<endl;
          
    cout<<" Please read the readme.txt file before beginning session."<<endl;
          
    cout<<" Developed by: Machewy"<<endl;
          
    cout<<" @copy righted"<<endl;
          
    cout<<" All rights reserved. "<<endl;
          
    cout<<endl;
          
    cout<<endl;
          
    system("PAUSE");
          
    system("CLS");
          
    cout<< "ftp>open ";
          
    cin.getline(szopenftp20);
          
    cout<<"_____________________________________________"<<endl;
          
    cout<<"connected to: "<<szopenftp<<endl;
          
    cout<<endl;
          
    cout<<"ftp>";
          
    cin.getline(szeditftp20);
          
    cout<<endl;
          
    cout<<"All commands including, "<<szeditftp<<","<<" have been disabled!"<<endl;
          
    cout<<"Please login:"<<endl;
          
    cout<<"User name:";
          
    cin.getline(szadminftp20);
           if(!
    strcmpi("Admin"szadminftp))
           {
            
    cout<<"Admin Password:";
            
    cin.getline(szpassftp20);
             if(!
    strcmpi("coolbeans"szpassftp))
             {
              
    system("CLS");
              
    cout<<" Correct Password. ";
              
    system("PAUSE");
             }
             else
             {
              
    cout<<" Invalid Password! "<<endl;
              
    cout<<" Logon failed. "<<endl;
              
    cout<<" disconnecting.... "<<endl;
              
    system("PAUSE");
             }
           }
           else
           {
            
    cout<<"Invalid user name!"<<endl;
            
    cout<<"Log on failed."<<endl;
            
    cout<<"disconnecting...."<<endl;
            
    system("PAUSE");
           }
          return 
    0;

    Does anyone know a better way?
    "All things come to an end"

  2. #2
    jasondoucette.com JasonD's Avatar
    Join Date
    Mar 2003
    Posts
    278
    I am not sure what you mean, but if you mean something better than using a nested-if statement, look into switch statments (case statements).

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Using char arrays in branching statements
    By hmanners in forum C Programming
    Replies: 18
    Last Post: 06-08-2009, 05:03 AM
  2. Char arrays, pointers and if statements
    By rocketman50 in forum C Programming
    Replies: 5
    Last Post: 02-22-2009, 11:11 AM
  3. Replies: 16
    Last Post: 01-01-2008, 04:07 PM
  4. arrays within switch statements
    By divinyl in forum C++ Programming
    Replies: 6
    Last Post: 07-17-2003, 02:56 PM
  5. Crazy memory problem with arrays
    By fusikon in forum C++ Programming
    Replies: 9
    Last Post: 01-15-2003, 09:24 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21