What does "expected unqualified-id before "IF"" mean, please help

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • erictheone
    New Member
    • Mar 2009
    • 13

    #1

    What does "expected unqualified-id before "IF"" mean, please help

    Ok so what I'm trying to do is create a trans location cipher. For those among us that don't know alot about cryptography it is a method for jumbling up letters to disguise linguistic patterns(words) . What it does is takes a string as a parameter, determines length of string, tests if the length is a perfect square, if it is then it makes a 2-d array with its length and height equal to the lengths root. If it isn't then it cuts it down to size that is a perfect square. Then it does some other stuff that is irrelevant for my problem. If anyone wants a complete explanation of the source just let me know. When i try to compile these error statements come up.

    1) at line 41- expected unqualified-id before "if"
    2)at line 41- expected `,' or `;' before "if"
    3)at line 44- expected unqualified-id before '||' token
    4)at line 44- expected `,' or `;' before '||' token
    5)at line 50- expected unqualified-id before "return"
    6)at line 50- expected `,' or `;' before "return"
    7)at line 51- expected declaration before '}' token

    here is the source, please help.
    Code:
    #include <string>
    #include <cstdlib>
    using namespace std;
    
    string tranString( string letters){
         int length = letters.length();
         int arrayLength;
         int arrayHeight;
         int extraLength = 0;
         int column;
         int subStr;
         int row;
         string beforeMix [arrayLength][arrayHeight];
         
         for ( int n = 1; n < length; n++){
             if( length % n == 0 && length / n == n){
             arrayLength = length / n;
             arrayHeight = arrayLength;
             bool perSquare = 0;
             n = length;
             }
             else if( (length - n) % n == 0 && (length  - n) / n == n ){
                  arrayLength = length - n;
                  arrayHeight = length - n;
                  extraLength = n;
                  }
    
         }
      
         for (row = 0 ; row <= arrayHeight - 1; row++){
             for ( column = 0, subStr = 0; column <= arrayLength - 1, subStr <= length - extraLength - 1; column++, subStr++){
             beforeMix[column][row] = letters.substr(subStr, 1);
             }
         }
         string newOrder = "";
         for( column = arrayLength - 1, subStr = 0; column > -1, subStr <= (letters.length() - 1); column-- , subStr++)
              for( row = arrayHeight - 1; row > -1; row--){
                     newOrder.substr( subStr, 1) = beforeMix[column][row];
                     }
         }
         if( newOrder.length() % 2 == 0;){
         newOrder.insert( (newOrder.length() / 2), letters.substr( (length - extraLength) - 1, extraLength));
         }
         else
         {
             newOrder.insert( ((newOrder.length() - 1) / 2), letters.substr( (length - extraLength) - 1, extraLength));
         }
         
              
         return letters;
         }
  • Savage
    Recognized Expert Top Contributor
    • Feb 2007
    • 1759

    #2
    Can you tell us what do you think that this does:

    Code:
      newOrder.substr( subStr, 1) = beforeMix[column][row];
    ?

    Also you don't need this ';' here:

    Code:
     if( newOrder.length() % 2 == 0;)
    :D

    ,regards

    Savage

    Comment

    • erictheone
      New Member
      • Mar 2009
      • 13

      #3
      Ok so I sort of found the problem, I was forgetting a "{" at line 36. The line is very long so i didn't see it. To savage, the code sets the designated sub string equal to the string, really just one letter. Now the code compiles, but it hangs. Again help would be appreciated :). This is the new code
      Code:
      #include <string>
      #include <cstdlib>
      using namespace std;
      
      string tranString( string letters){
           int length = letters.length();
           int arrayLength;
           int arrayHeight;
           int extraLength = 0;
           int column;
           int subStr;
           int row;
           string beforeMix [arrayLength][arrayHeight];
           for ( int n = 1; n < length; n++){
               if( length % n == 0 && length / n == n){
               arrayLength = length / n;
               arrayHeight = arrayLength;
               bool perSquare = 0;
               n = length;
               }
               else if( (length - n) % n == 0 && (length  - n) / n == n ){
                    arrayLength = length - n;
                    arrayHeight = length - n;
                    extraLength = n;
                    }
      
           }
           
        
           for (row = 0 ; row <= arrayHeight - 1; row++){
               for ( column = 0, subStr = 0; column <= arrayLength - 1, subStr <= length - extraLength - 1; column++, subStr++){
               beforeMix[column][row] = letters.substr(subStr, 1);
               }
           }
           string newOrder;
           for( column = arrayLength - 1, subStr = 0; column > -1, subStr <= (letters.length() - 1); column-- , subStr++){
                 for( row = arrayHeight - 1; row > -1; row--){
                       newOrder.substr( subStr, 1) = beforeMix[column][row];
                       }
           }
           if( newOrder.length() % 2 == 0){
           newOrder.insert( (newOrder.length() / 2), letters.substr( (length - extraLength) - 1, extraLength));
           }
           else
           {
               newOrder.insert( ((newOrder.length() - 1) / 2), letters.substr( (length - extraLength) - 1, extraLength));
           }
           
                
           return newOrder;
           }

      Comment

      • Savage
        Recognized Expert Top Contributor
        • Feb 2007
        • 1759

        #4
        Code:
          for( column = arrayLength - 1, subStr = 0; column > -1, subStr <= (letters.length() - 1); column-- , subStr++)
        {
                   for( row = arrayHeight - 1; row > -1; row--)
                   {
                         newOrder.substr( subStr, 1) = beforeMix[column][row];
                  }
        }
        Why are the conditions in for loop for column and row >-1?
        And this:

        Code:
        newOrder.substr( subStr, 1) = beforeMix[column][row];
        doesn't do what you think it does.This creates a new string of 1 letter length,and then it assigns to that string beforeMix[column][row].If you wish to change a single letter in the string you can use the std::string's overloaded operator[],just like you would change an element of an array.If you wish to replace more then one letter you can use std::string::re place

        ,regards

        Savage

        Comment

        • erictheone
          New Member
          • Mar 2009
          • 13

          #5
          K so I should have seen the -1. I was using that before I remembered =>. So I will change that. And thanks for the string thing, I would have never caught that. Hopefully it will work now. Vielen Dank!!!

          Comment

          • erictheone
            New Member
            • Mar 2009
            • 13

            #6
            Ok so I think I'm getting somewhere, but no it isn't hanging it just isn't compiling.
            Here are the error messages.
            1)38 no matching function for call to `std::basic_str ing<char, std::char_trait s<char>, std::allocator< char> >::replace(int& , <unknown type>, std::string&)'
            2)39 request for member `length' in `beforeMix', which is of non-class type `std::string[((unsigned int)((int)array Length))][((unsigned int)((int)array Height))]'

            Again Help would be much appreciated.

            Code:
            #include <string>
            #include <cstdlib>
            using namespace std;
            
            string tranString( string letters){
                 int length = letters.length();
                 int arrayLength;
                 int arrayHeight;
                 int extraLength = 0;
                 int column;
                 int subStr;
                 int row;
                 string beforeMix [arrayLength][arrayHeight];
                 
                 for ( int n = 1; n < length; n++){
                     if( length % n == 0 && length / n == n){
                     arrayLength = length / n;
                     arrayHeight = arrayLength;
                     bool perSquare = 0;
                     n = length;
                     }
                     else if( (length - n) % n == 0 && (length  - n) / n == n ){
                          arrayLength = length - n;
                          arrayHeight = length - n;
                          extraLength = n;
                          }
            
                 }
              
                 for (row = 0 ; row <= arrayHeight - 1; row++){
                     for ( column = 0, subStr = 0; column <= arrayLength - 1, subStr <= length - extraLength - 1; column++, subStr++){
                     beforeMix[column][row] = letters.substr(subStr, 1);
                     }
                 }
                 string newOrder;
                 for( column = arrayLength - 1, subStr = 0; column >= 0, subStr <= (letters.length() - 1); column--){
                       for( row = arrayHeight - 1; row >= 0; row--){
                             newOrder.replace(subStr, beforeMix[column][row].length, beforeMix[column][row]);
                             subStr = (beforeMix.length[column][row].length) - 1;
                             }
                 }
                 if( newOrder.length() % 2 == 0){
                 newOrder.insert( (newOrder.length() / 2), letters.substr( (length - extraLength) - 1, extraLength));
                 }
                 else
                 {
                     newOrder.insert( ((newOrder.length() - 1) / 2), letters.substr( (length - extraLength) - 1, extraLength));
                 }
                 
                      
                 return newOrder;
                 }

            Comment

            • newb16
              Contributor
              • Jul 2008
              • 687

              #7
              Add ()'s to length call.

              Comment

              • erictheone
                New Member
                • Mar 2009
                • 13

                #8
                Ow boy... I feel retarded... Thanks a million though!

                Comment

                • erictheone
                  New Member
                  • Mar 2009
                  • 13

                  #9
                  K, the program is back to hanging. Here is the source.

                  Code:
                  #include <string>
                  #include <cstdlib>
                  using namespace std;
                  string tranString( string letters){
                       getline (cin, letters);
                       int Length = letters.length();
                       int arrayLength;
                       int arrayHeight;
                       int extraLength = 0;
                       int column;
                       int subStr;
                       int row;
                       string beforeMix [arrayLength][arrayHeight];
                       
                       for ( int n = 1; n < Length; n++){
                           if( Length % n == 0 && Length / n == n){
                           arrayLength = Length / n;
                           arrayHeight = arrayLength;
                           bool perSquare = 0;
                           n = Length;
                           }
                           else if( (Length - n) % n == 0 && (Length  - n) / n == n ){
                                arrayLength = Length - n;
                                arrayHeight = Length - n;
                                extraLength = n;
                                }
                  
                       }
                    
                       for (row = 0 ; row <= arrayHeight - 1; row++){
                           for ( column = 0, subStr = 0; column <= arrayLength - 1, subStr <= Length - extraLength - 1; column++, subStr++){
                           beforeMix[column][row] = letters.substr(subStr, 1);
                           }
                       }
                       string newOrder;
                       for( column = arrayLength - 1, subStr = 0; column >= 0, subStr <= (letters.length() - 1); column--){
                             for( row = arrayHeight - 1; row >= 0; row--){
                                   newOrder.replace(subStr, beforeMix[column][row].length(), beforeMix[column][row]);
                                   subStr = (beforeMix[column][row].length()) - 1;
                                   }
                       }
                       if( newOrder.length() % 2 == 0){
                       newOrder.insert( (newOrder.length() / 2), letters.substr( (Length - extraLength) - 1, extraLength));
                       }
                       else
                       {
                           newOrder.insert( ((newOrder.length() - 1) / 2), letters.substr( (Length - extraLength) - 1, extraLength));
                       }
                       
                            
                      return newOrder;
                  }

                  Comment

                  • erictheone
                    New Member
                    • Mar 2009
                    • 13

                    #10
                    one last revision before I go to sleep
                    Code:
                    #include <string>
                    #include <cstdlib>
                    using namespace std;
                    
                    string tranString( string letters){
                         //determines length of letters
                         int stringLength = letters.size();
                         //preps before mix dimensions
                         int arraySize = 1;
                         int arrayHeight = 1;
                         //sets extralength = 0
                         int extraLength = 0;
                         //initalizes positions in array and string
                         int column = 0;
                         int row = 0;
                         int subStr = 0;
                         //initalizes array for text, As of march 16 it goes this far
                         string beforeMix[arraySize][arrayHeight];
                         //determines if stringlength is a perfect square
                         for ( int n = 1; n <= stringLength; n++){
                             if( stringLength % n == 0 && (stringLength / n) == n){
                             arraySize = stringLength / n;
                             arrayHeight = arraySize;
                             n = stringLength;
                             }
                             else if( (stringLength - n) % n == 0 && (stringLength  - n) / n == n ){
                                  arraySize = stringLength - n;
                                  arrayHeight = stringLength - n;
                                  extraLength = n;
                                  }
                    
                         }
                      
                         for (row = 0 ; row <= arrayHeight - 1; row++){
                             for ( column = 0, subStr = 0; column <= arraySize - 1, subStr <= stringLength - extraLength - 1; column++, subStr++){
                             beforeMix[column][row] = letters.substr(subStr, 1);
                             }
                         }
                         string newOrder;
                         for( column = arraySize - 1, subStr = 0; column >= 0, subStr <= (letters.length() - 1); column--){
                               for( row = arrayHeight - 1; row >= 0; row--){
                                     newOrder.replace(subStr, beforeMix[column][row].length(), beforeMix[column][row]);
                                     subStr = (beforeMix[column][row].length()) - 1;
                                     }
                         }
                         if( newOrder.length() % 2 == 0){
                         newOrder.insert( (newOrder.length() / 2), letters.substr( (stringLength - extraLength) - 1, extraLength));
                         }
                         else
                         {
                             newOrder.insert( ((newOrder.length() - 1) / 2), letters.substr( (stringLength - extraLength) - 1, extraLength));
                         }
                         
                              
                        return newOrder;
                    }

                    Comment

                    Working...