Thread: switch()

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Dec 2007
    Posts
    932

    switch()

    I would need some help using switch() statement.
    We should use switch() statement instead of if() if we have a lot of conditions.
    For keeping it simple i only use two conditions here though.

    I dont really understand what to put in the place of expression
    switch (expression)
    {
    case valueOne: statement;
    break;
    case valueTwo: statement;
    break;
    default: statement;
    }

    That would be the if() version and i would like that both if() would be true and then to do something after
    Code:
    if  (str1[pos-3] != ' '  &&  
         str1[pos-2] != 'a' ) 
    {
        if  (str1[pos-4] != ' ' && 
             str1[pos-3] != 'a' && 
             str1[pos-2] != 'n' )
            
                        str1[pos] = toupper (str1[pos]);
                              pos += str2.size();
    }
    Code:
    int main (){
       
       ifstream  file1;
       openFile(file1);
       ifstream  file2 ("List of proper nouns.txt");
       ofstream TheCopy;
       TheCopy.open ("Your_Uppercased_Proper_Nouns_Copy.srt",ios::app);
       string str1;
       string str2;
       vector<string> myvector;
       size_t pos = 0;
          
       while (getline(file2, str2)){
               
           myvector.push_back(str2);
       }
           
       while (getline(file1, str1)){
                    
             for ( int i = 0; i < myvector.size(); i++){
                        
                    while ((pos = str1.find(myvector[i], pos)) != string::npos){
                             
                          if  (str1[pos-3] != ' ' &&  
                               str1[pos-2] != 'a' ){ 
                          
                                if  (str1[pos-4] != ' ' && 
                                     str1[pos-3] != 'a' && 
                                     str1[pos-2] != 'n' )
                                    
                                     str1[pos] = toupper (str1[pos]);
                                     pos += str2.size();
                           }              
                    }
             }
             TheCopy << str1 << endl;
       }
       file2.close();
       TheCopy.close();
       return 0;
    }
    Last edited by Ducky; 03-03-2008 at 01:51 PM.
    Using Windows 10 with Code Blocks and MingW.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Data Structure Eror
    By prominababy in forum C Programming
    Replies: 3
    Last Post: 01-06-2009, 09:35 AM
  2. ascii rpg help
    By aaron11193 in forum C Programming
    Replies: 18
    Last Post: 10-29-2006, 01:45 AM
  3. Switch
    By cogeek in forum C Programming
    Replies: 4
    Last Post: 12-23-2004, 06:40 PM
  4. Switch Case
    By FromHolland in forum C++ Programming
    Replies: 7
    Last Post: 06-13-2003, 03:51 AM