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. - #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;
-
}
-
-
9 27302
Can you tell us what do you think that this does: - newOrder.substr( subStr, 1) = beforeMix[column][row];
?
Also you don't need this ';' here: - if( newOrder.length() % 2 == 0;)
:D
,regards
Savage
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 - #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;
-
}
- 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: - 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
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!!!
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. - #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;
-
}
-
-
Ow boy... I feel retarded... Thanks a million though!
K, the program is back to hanging. Here is the source. - #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;
-
}
one last revision before I go to sleep - #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;
-
}
-
-
-
Post your reply Sign in to post your reply or Sign up for a free account.
Similar topics
2 posts
views
Thread by Ng Pheng Siong |
last post: by
|
20 posts
views
Thread by Steven T. Hatton |
last post: by
|
2 posts
views
Thread by Paul T. Rong |
last post: by
|
2 posts
views
Thread by hsharsha |
last post: by
|
39 posts
views
Thread by utab |
last post: by
|
7 posts
views
Thread by =?Utf-8?B?UGV0ZXI=?= |
last post: by
|
9 posts
views
Thread by PengYu.UT |
last post: by
|
4 posts
views
Thread by dolphin |
last post: by
|
13 posts
views
Thread by bobby |
last post: by
|
2 posts
views
Thread by Blau |
last post: by
| | | | | | | | | | | |