Search code examples
c++game-engine

inputing char for a symmetric cipher to be used in a game


I am looking for a simple function that would allow an user (player) to assign letters of the alphabet to other letters. For example: "a = n" . Then placing theses letters in an array: alb[n,..]. Should I use pointers?


Solution

  • I have the answer. Here some test code that uses the first three letters of the alphabet.

    int i = 0, j = 0;
    string alp[] = { "a", "b", "c" }, alpc[] = { "0", "1", "2" };
    
    while (i <= 2) {
        cout << "Enter the letter substitution: " << alp[i] << " = ";
        cin >> alpc[i];
        for (j = 0; j < i; ++j) {
            while (alpc[j] == alpc[i]) {
                cout << "Please enter a non-redundant letter substitution: ";
                cin >> alpc[i];
            }
    
        }
        ++i;
        }