hello all,
I've posted an old version of the following code before but I was not clear on my question or the title of the problem [for that am sorry]
I did changes on the code now I have no errors but it does not do what I want ..
lets say there is a sentence like this "helloworld" is saved in an arry called original the unlocking charcter is "W" .. the code searches for the "w" when it finds the "w" it saves it and what is after it in a new array of charcters called first .. however before it finds the "w" it should save the letters in an array called second .. at last it refills the array original with array first and when it is done it fills it with array second ...
please see the crazy part of my code "commented as crazy part"
here is my code:
//This program takes the number of rings, the unlocking word and the secret word in the form of _T___ that is with knowing
//only one charcter of the word.
//The program then takes the cryptx (rings==lines of the cryptx)
//each line has 26 different letters
//The program should align the unlocking word and thus the secret word appears
//The program only outputs the unlocking word and the secret word
# include <iostream>
# include <string>
using namespace std;
int main()
{
string un_lock;
string secret;
int rings;
char string_in[1000][26];//[rings][letters]
char second[1000][26];
char first[1000][26];
char sec_char;
int sec_pos;
int the_col;
string the_secret;
cout<<"Enter the number of the rings"<<endl;
cin>>rings;
cout<<"Enter the Unlocking word"<<endl;
cin>>un_lock;
cout<<"Enter the secret word"<<endl;
cin>>secret;
cout<<"Enter the cryptx"<<endl;
for(int i=0; i<rings; i++)
for(int j=0; j<26; j++)
cin>>string_in[i][j];
//this is the crazy part
for(int j=0; j<rings; j++)
{
for(int i=0; i<26; i++)
{
if (string_in[j][i]!=un_lock[j] )
second[j][i]=string_in [j][i];
else if (string_in[j][i]==un_lock[j])
for (int z=0, y=i; z<26-y; z++)
first[j][z]=string_in[j][i++];
}
}
//to fill in the main string again
for(int j=0; j<rings; j++)
{
int i;
for( i=0; first[j][i]!='\0'; i++)
string_in[j][i]=first[j][i];
for(int p=0, z=0; second[p][z]!='\0'; z++, p++)
string_in[j][i++]=second[p][z];
} // end of crazy part
//finding the position of the known secret letter
//which will be the number of the ring it is located in
for(int i=0; i<rings; i++)
if(static_cast<int>(secret[i])!=95)
{
sec_char=secret[i];
sec_pos=i;
}
//finding the column of the secret word
for(int i=0; i<26; i++)
if(static_cast<int>(string_in[sec_pos][i])==static_cast<int>(sec_char))
the_col=i;
//saving the secret word
for(int j=0; j<rings; j++)
the_secret[j]=string_in[j][the_col];
//the output
cout<<un_lock<<" "<<the_secret<<endl;
return 0;
}
I entered the number of rings : 5
the unlocking word: GREEN (ALL CAPITAL)
the secret word: _P___ (WITH UNDERSCORES)
the cryptx is as follows :
KFZLQMDWJUSHGCEIXRAOPNVTYB
IMWZPFJBKLTNOEQDHUXGVYASRC
FAMIETZORWPSQUNGLDYBKXHCVJ
XNAKVPICQHDFWEGBRTMLZOUSYJ
ZSYFDOWIJCAKPBTXLRUNGQMVHE
why does it stop after the input of the cryptx??
please help asap :(