473,399 Members | 3,038 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

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.
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
9 27586
Savage
1,764 Expert 1GB
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
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
1,764 Expert 1GB
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
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
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
newb16
687 512MB
Add ()'s to length call.
Mar 16 '09 #7
Ow boy... I feel retarded... Thanks a million though!
Mar 16 '09 #8
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
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

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

Similar topics

2
by: Ng Pheng Siong | last post by:
Hi, I just noticed that demo/evp_ciph_test.py of my M2Crypto package causes a core dump. It used to not do that. ;-) The core dump happens when the program is exiting; in the output below,...
20
by: Steven T. Hatton | last post by:
I just read this in the description of how C++ is supposed to be implemented: "All external object and function references are resolved. Library components are linked to satisfy external...
2
by: Paul T. Rong | last post by:
Sorry I just lost tracks of a series of posts, so I post my question again, hoping someone can help. Here is codes provided by Jeff Smith > Private Sub Form_Load() > Dim db As...
2
by: hsharsha | last post by:
Consider the below code: int main(void) { class inner {}; friend class inner; /* what does this signify???? */ return 0; }
39
by: utab | last post by:
Dear all, Is there a clear distinction how to decide which functions to be members of a class and which not How is your attitude (Your general way from your experiences ...) "If the...
7
by: =?Utf-8?B?UGV0ZXI=?= | last post by:
Dim sCoName As String = oDs.Customers(0).CompanyName The part that I want to understand is the oDs.Customers(0). Does oDs.Customers(0) mean 1st row of the datatable Customers. Where can I find...
9
by: PengYu.UT | last post by:
Hi, I'm wondering what 'c' in "cout", "cin" mean? Does it mean "C++"? Or the 'c' in <cassert>? Thanks, Peng
4
by: dolphin | last post by:
Hi All I read a .cpp files,find that static void fun(void){......} int main() { .......... } What does this static function mean?Is it the same as the static
13
by: bobby | last post by:
hello group, what does for( ; ; ) mean in C program Thanks
2
by: Blau | last post by:
I am trying to follow some tutorials, and I came across this bit of code: public void AddBackground(string backgroundKey, string textureName, Vector2 position, Rectangle? sourceRect, float...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.