How to go back to
start_new_input:
of main() function?
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
//global varibals:
char entered_characters[9999];
int direction_of_rotor1;
int direction_of_rotor2;
char alphabet_of_rotor1[26];
char alphabet_of_rotor2[26];
char rotor1_backward(char Letter);
char rotor1_forward(char Letter);
char rotor2_backward(char Letter2);
char rotor2_forward(char Letter2);
char print(char print_char);
int main()
{
cout << "This is enigma machine:" << endl;
cout << "*NOTE:This programe accepts only lower case letters" << endl;
cout<<"--------------------------------------------------------------"<<endl;
cout << "Enter letters for the first rotor:" << endl;
cin >> alphabet_of_rotor1;
cout<<"--------------------------------------------------------------"<<endl;
cout << "Enter letters for the second rotor:" << endl;
cin >> alphabet_of_rotor2;
cout<<"--------------------------------------------------------------"<<endl;
cout << "Chose direction of rotor 1:" << endl;
cout << "*(i.e.:enter 1 for left and 2 for right)" << endl;
cin >> direction_of_rotor1;
cout<<"--------------------------------------------------------------"<<endl;
int going_through_entered_characters_array=-1;
cout << "Enter letter to encode:" << endl;
cin >> entered_characters;
start_new_input: /* null statement required *///don't remove these 3 signs!!!
char Letter;
going_through_entered_characters_array++;
Letter = entered_characters[going_through_entered_characters_array];
if(entered_characters[going_through_entered_characters_array] != '\0')
{
switch(direction_of_rotor1)
{
case 1:
cout<<"--------------------------------------------------------------"<<endl;
rotor1_backward(Letter);
break;
case 2:
cout<<"--------------------------------------------------------------"<<endl;
rotor1_forward(Letter);
break;
default:
cout<<"--------------------------------------------------------------"<<endl;
cout << "Wrong choice" <<endl;
break;
}
}
else
{
cout << "\nend of program...";
system("PAUSE");
}
return 0;
}
//--------------------------------------------------------------
//--------------------------------------------------------------
char rotor1_backward(char Letter)
{
for (int alphabet1=0;alphabet1<26;alphabet1++)
{
if(alphabet_of_rotor1[alphabet1] == Letter)
{
cout << "Chose direction of rotor 2:" << endl;
cout << "*(i.e.:enter 1 for left and 2 for right)" << endl;
cin >> direction_of_rotor2;
switch(direction_of_rotor2)
{
case 1:
cout<<"--------------------------------------------------------------"<<endl;
rotor2_backward(alphabet_of_rotor1[alphabet1-1]);
case 2:
cout<<"--------------------------------------------------------------"<<endl;
rotor2_forward(alphabet_of_rotor1[alphabet1-1]);
default:
cout<<"--------------------------------------------------------------"<<endl;
cout << "Wrong choice 2.1" <<endl;
}
}
}
return 0;
}
//--------------------------------------------------------------
//--------------------------------------------------------------
char rotor1_forward(char Letter)
{
for (int alphabet1=0;alphabet1<26;alphabet1++)
{
if(alphabet_of_rotor1[alphabet1] == Letter)
{
cout << "Chose direction of rotor 2:" << endl;
cout << "*(i.e.:enter 1 for left and 2 for right)" << endl;
cin >> direction_of_rotor2;
switch(direction_of_rotor2)
{
case 1:
cout<<"--------------------------------------------------------------"<<endl;
rotor2_backward(alphabet_of_rotor1[alphabet1+1]);
break;
case 2:
cout<<"--------------------------------------------------------------"<<endl;
rotor2_forward(alphabet_of_rotor1[alphabet1+1]);
break;
default:
cout<<"--------------------------------------------------------------"<<endl;
cout << "Wrong choice 2.2" <<endl;
break;
}
break;
}
}
return 0;
}
//--------------------------------------------------------------
//--------------------------------------------------------------
char rotor2_backward(char Letter2)
{
for (int alphabet2=0;alphabet2<26;alphabet2++)
{
if(alphabet_of_rotor2[alphabet2] == Letter2)
{
print(alphabet_of_rotor2[alphabet2-1]);
}
}
return 0;
}
//--------------------------------------------------------------
//--------------------------------------------------------------
char rotor2_forward(char Letter2)
{
for (int alphabet2=0;alphabet2<26;alphabet2++)
{
if(alphabet_of_rotor2[alphabet2] == Letter2)
{
print(alphabet_of_rotor2[alphabet2+1]);
}
}
return 0;
}
//--------------------------------------------------------------
//--------------------------------------------------------------
//--------------------------------------------------------------
//--------------------------------------------------------------
char print(char print_char)
{
cout << print_char << endl;
goto start_new_input;
return 0;
}