By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,360 Members | 3,011 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,360 IT Pros & Developers. It's quick & easy.

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

P: 13
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.
Expand|Select|Wrap|Line Numbers
  1. #include <string>
  2. #include <cstdlib>
  3. using namespace std;
  4.  
  5. string tranString( string letters){
  6.      int length = letters.length();
  7.      int arrayLength;
  8.      int arrayHeight;
  9.      int extraLength = 0;
  10.      int column;
  11.      int subStr;
  12.      int row;
  13.      string beforeMix [arrayLength][arrayHeight];
  14.  
  15.      for ( int n = 1; n < length; n++){
  16.          if( length % n == 0 && length / n == n){
  17.          arrayLength = length / n;
  18.          arrayHeight = arrayLength;
  19.          bool perSquare = 0;
  20.          n = length;
  21.          }
  22.          else if( (length - n) % n == 0 && (length  - n) / n == n ){
  23.               arrayLength = length - n;
  24.               arrayHeight = length - n;
  25.               extraLength = n;
  26.               }
  27.  
  28.      }
  29.  
  30.      for (row = 0 ; row <= arrayHeight - 1; row++){
  31.          for ( column = 0, subStr = 0; column <= arrayLength - 1, subStr <= length - extraLength - 1; column++, subStr++){
  32.          beforeMix[column][row] = letters.substr(subStr, 1);
  33.          }
  34.      }
  35.      string newOrder = "";
  36.      for( column = arrayLength - 1, subStr = 0; column > -1, subStr <= (letters.length() - 1); column-- , subStr++)
  37.           for( row = arrayHeight - 1; row > -1; row--){
  38.                  newOrder.substr( subStr, 1) = beforeMix[column][row];
  39.                  }
  40.      }
  41.      if( newOrder.length() % 2 == 0;){
  42.      newOrder.insert( (newOrder.length() / 2), letters.substr( (length - extraLength) - 1, extraLength));
  43.      }
  44.      else
  45.      {
  46.          newOrder.insert( ((newOrder.length() - 1) / 2), letters.substr( (length - extraLength) - 1, extraLength));
  47.      }
  48.  
  49.  
  50.      return letters;
  51.      }
  52.  
  53.  
Mar 14 '09 #1
Share this Question
Share on Google+
9 Replies


Savage
Expert 100+
P: 1,764
Can you tell us what do you think that this does:

Expand|Select|Wrap|Line Numbers
  1.   newOrder.substr( subStr, 1) = beforeMix[column][row];
?

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

Expand|Select|Wrap|Line Numbers
  1.  if( newOrder.length() % 2 == 0;)
:D

,regards

Savage
Mar 14 '09 #2

P: 13
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
Expand|Select|Wrap|Line Numbers
  1. #include <string>
  2. #include <cstdlib>
  3. using namespace std;
  4.  
  5. string tranString( string letters){
  6.      int length = letters.length();
  7.      int arrayLength;
  8.      int arrayHeight;
  9.      int extraLength = 0;
  10.      int column;
  11.      int subStr;
  12.      int row;
  13.      string beforeMix [arrayLength][arrayHeight];
  14.      for ( int n = 1; n < length; n++){
  15.          if( length % n == 0 && length / n == n){
  16.          arrayLength = length / n;
  17.          arrayHeight = arrayLength;
  18.          bool perSquare = 0;
  19.          n = length;
  20.          }
  21.          else if( (length - n) % n == 0 && (length  - n) / n == n ){
  22.               arrayLength = length - n;
  23.               arrayHeight = length - n;
  24.               extraLength = n;
  25.               }
  26.  
  27.      }
  28.  
  29.  
  30.      for (row = 0 ; row <= arrayHeight - 1; row++){
  31.          for ( column = 0, subStr = 0; column <= arrayLength - 1, subStr <= length - extraLength - 1; column++, subStr++){
  32.          beforeMix[column][row] = letters.substr(subStr, 1);
  33.          }
  34.      }
  35.      string newOrder;
  36.      for( column = arrayLength - 1, subStr = 0; column > -1, subStr <= (letters.length() - 1); column-- , subStr++){
  37.            for( row = arrayHeight - 1; row > -1; row--){
  38.                  newOrder.substr( subStr, 1) = beforeMix[column][row];
  39.                  }
  40.      }
  41.      if( newOrder.length() % 2 == 0){
  42.      newOrder.insert( (newOrder.length() / 2), letters.substr( (length - extraLength) - 1, extraLength));
  43.      }
  44.      else
  45.      {
  46.          newOrder.insert( ((newOrder.length() - 1) / 2), letters.substr( (length - extraLength) - 1, extraLength));
  47.      }
  48.  
  49.  
  50.      return newOrder;
  51.      }
Mar 14 '09 #3

Savage
Expert 100+
P: 1,764
Expand|Select|Wrap|Line Numbers
  1.   for( column = arrayLength - 1, subStr = 0; column > -1, subStr <= (letters.length() - 1); column-- , subStr++)
  2. {
  3.            for( row = arrayHeight - 1; row > -1; row--)
  4.            {
  5.                  newOrder.substr( subStr, 1) = beforeMix[column][row];
  6.           }
  7. }
  8.  
Why are the conditions in for loop for column and row >-1?
And this:

Expand|Select|Wrap|Line Numbers
  1. 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::replace

,regards

Savage
Mar 15 '09 #4

P: 13
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!!!
Mar 15 '09 #5

P: 13
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_string<char, std::char_traits<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)arrayLength))][((unsigned int)((int)arrayHeight))]'

Again Help would be much appreciated.

Expand|Select|Wrap|Line Numbers
  1. #include <string>
  2. #include <cstdlib>
  3. using namespace std;
  4.  
  5. string tranString( string letters){
  6.      int length = letters.length();
  7.      int arrayLength;
  8.      int arrayHeight;
  9.      int extraLength = 0;
  10.      int column;
  11.      int subStr;
  12.      int row;
  13.      string beforeMix [arrayLength][arrayHeight];
  14.  
  15.      for ( int n = 1; n < length; n++){
  16.          if( length % n == 0 && length / n == n){
  17.          arrayLength = length / n;
  18.          arrayHeight = arrayLength;
  19.          bool perSquare = 0;
  20.          n = length;
  21.          }
  22.          else if( (length - n) % n == 0 && (length  - n) / n == n ){
  23.               arrayLength = length - n;
  24.               arrayHeight = length - n;
  25.               extraLength = n;
  26.               }
  27.  
  28.      }
  29.  
  30.      for (row = 0 ; row <= arrayHeight - 1; row++){
  31.          for ( column = 0, subStr = 0; column <= arrayLength - 1, subStr <= length - extraLength - 1; column++, subStr++){
  32.          beforeMix[column][row] = letters.substr(subStr, 1);
  33.          }
  34.      }
  35.      string newOrder;
  36.      for( column = arrayLength - 1, subStr = 0; column >= 0, subStr <= (letters.length() - 1); column--){
  37.            for( row = arrayHeight - 1; row >= 0; row--){
  38.                  newOrder.replace(subStr, beforeMix[column][row].length, beforeMix[column][row]);
  39.                  subStr = (beforeMix.length[column][row].length) - 1;
  40.                  }
  41.      }
  42.      if( newOrder.length() % 2 == 0){
  43.      newOrder.insert( (newOrder.length() / 2), letters.substr( (length - extraLength) - 1, extraLength));
  44.      }
  45.      else
  46.      {
  47.          newOrder.insert( ((newOrder.length() - 1) / 2), letters.substr( (length - extraLength) - 1, extraLength));
  48.      }
  49.  
  50.  
  51.      return newOrder;
  52.      }
  53.  
  54.  
Mar 16 '09 #6

100+
P: 687
Add ()'s to length call.
Mar 16 '09 #7

P: 13
Ow boy... I feel retarded... Thanks a million though!
Mar 16 '09 #8

P: 13
K, the program is back to hanging. Here is the source.

Expand|Select|Wrap|Line Numbers
  1. #include <string>
  2. #include <cstdlib>
  3. using namespace std;
  4. string tranString( string letters){
  5.      getline (cin, letters);
  6.      int Length = letters.length();
  7.      int arrayLength;
  8.      int arrayHeight;
  9.      int extraLength = 0;
  10.      int column;
  11.      int subStr;
  12.      int row;
  13.      string beforeMix [arrayLength][arrayHeight];
  14.  
  15.      for ( int n = 1; n < Length; n++){
  16.          if( Length % n == 0 && Length / n == n){
  17.          arrayLength = Length / n;
  18.          arrayHeight = arrayLength;
  19.          bool perSquare = 0;
  20.          n = Length;
  21.          }
  22.          else if( (Length - n) % n == 0 && (Length  - n) / n == n ){
  23.               arrayLength = Length - n;
  24.               arrayHeight = Length - n;
  25.               extraLength = n;
  26.               }
  27.  
  28.      }
  29.  
  30.      for (row = 0 ; row <= arrayHeight - 1; row++){
  31.          for ( column = 0, subStr = 0; column <= arrayLength - 1, subStr <= Length - extraLength - 1; column++, subStr++){
  32.          beforeMix[column][row] = letters.substr(subStr, 1);
  33.          }
  34.      }
  35.      string newOrder;
  36.      for( column = arrayLength - 1, subStr = 0; column >= 0, subStr <= (letters.length() - 1); column--){
  37.            for( row = arrayHeight - 1; row >= 0; row--){
  38.                  newOrder.replace(subStr, beforeMix[column][row].length(), beforeMix[column][row]);
  39.                  subStr = (beforeMix[column][row].length()) - 1;
  40.                  }
  41.      }
  42.      if( newOrder.length() % 2 == 0){
  43.      newOrder.insert( (newOrder.length() / 2), letters.substr( (Length - extraLength) - 1, extraLength));
  44.      }
  45.      else
  46.      {
  47.          newOrder.insert( ((newOrder.length() - 1) / 2), letters.substr( (Length - extraLength) - 1, extraLength));
  48.      }
  49.  
  50.  
  51.     return newOrder;
  52. }
Mar 16 '09 #9

P: 13
one last revision before I go to sleep
Expand|Select|Wrap|Line Numbers
  1. #include <string>
  2. #include <cstdlib>
  3. using namespace std;
  4.  
  5. string tranString( string letters){
  6.      //determines length of letters
  7.      int stringLength = letters.size();
  8.      //preps before mix dimensions
  9.      int arraySize = 1;
  10.      int arrayHeight = 1;
  11.      //sets extralength = 0
  12.      int extraLength = 0;
  13.      //initalizes positions in array and string
  14.      int column = 0;
  15.      int row = 0;
  16.      int subStr = 0;
  17.      //initalizes array for text, As of march 16 it goes this far
  18.      string beforeMix[arraySize][arrayHeight];
  19.      //determines if stringlength is a perfect square
  20.      for ( int n = 1; n <= stringLength; n++){
  21.          if( stringLength % n == 0 && (stringLength / n) == n){
  22.          arraySize = stringLength / n;
  23.          arrayHeight = arraySize;
  24.          n = stringLength;
  25.          }
  26.          else if( (stringLength - n) % n == 0 && (stringLength  - n) / n == n ){
  27.               arraySize = stringLength - n;
  28.               arrayHeight = stringLength - n;
  29.               extraLength = n;
  30.               }
  31.  
  32.      }
  33.  
  34.      for (row = 0 ; row <= arrayHeight - 1; row++){
  35.          for ( column = 0, subStr = 0; column <= arraySize - 1, subStr <= stringLength - extraLength - 1; column++, subStr++){
  36.          beforeMix[column][row] = letters.substr(subStr, 1);
  37.          }
  38.      }
  39.      string newOrder;
  40.      for( column = arraySize - 1, subStr = 0; column >= 0, subStr <= (letters.length() - 1); column--){
  41.            for( row = arrayHeight - 1; row >= 0; row--){
  42.                  newOrder.replace(subStr, beforeMix[column][row].length(), beforeMix[column][row]);
  43.                  subStr = (beforeMix[column][row].length()) - 1;
  44.                  }
  45.      }
  46.      if( newOrder.length() % 2 == 0){
  47.      newOrder.insert( (newOrder.length() / 2), letters.substr( (stringLength - extraLength) - 1, extraLength));
  48.      }
  49.      else
  50.      {
  51.          newOrder.insert( ((newOrder.length() - 1) / 2), letters.substr( (stringLength - extraLength) - 1, extraLength));
  52.      }
  53.  
  54.  
  55.     return newOrder;
  56. }
  57.  
  58.  
  59.  
Mar 17 '09 #10

Post your reply

Sign in to post your reply or Sign up for a free account.