#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;


    //***i need to return to here and not to the beginning of main function***


    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;                //i intend to move these 
                    cout << "*(i.e.:enter 1 for left and 2 for right)" << endl;   //lines to main so
                    cin >> direction_of_rotor2;                                   //program wouldn't ask
                    switch(direction_of_rotor2)                                   //direction of rotor 2
                    {                                                             //on every letter
                    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;
                    }
           }
       }
    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;
                    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;
    //***i need to get from this line of this function here back to main***
    return 0;
}

Edited 4 Years Ago by 111100/11000

111100/11000
Deleted Member

Instead of trying to get back to the middle of a function why dont you just break it up into multiple functions to begin with? Something like:

int main () {
   /*
      do all output thing here as you already have
   */
   cout << "This is enigma machine:" << endl;
   // ...

   call_main_loop ();
   return 0;
}

void call_main_loop () {

   /* 
      Starting from where you'd like to loop back to
   */
   char Letter;
   going_through_entered_characters_array++;
   // ...
}

That way, to get back to that point, you just call call_main_loop.

Comments
Thnx it worked
This question has already been answered. Start a new discussion instead.