As the title suggest this is about problems I have having with writing my Caesar Cipher. I know how they work but I don't know exactly how to write it. And I know that many of you are wondering why I just don't read the hundreds of other Caesar Cipher posts, and I have. They aren't helping me. Everyone is using fstream and strings and other things that we haven't learned in my class therefore we can't use it. The two main questions I have are:

1) Is my option 1 properly accepting what the user inputs?
2) How in the world do I do the letter shift?

Here's the code:

#include <iostream>

using namespace std;

int main ()
{

    int choice;
    char word[140];
    char new_word[140];
    int Letter_Amount;
    char Answer;
    int shifts;
    char alphabet[27] = {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
    char new_alphabet[27];


    bool flag=false;
    bool flag_2=false;
    do {
        cout << "Ceaser Cipher v2.0" << endl;
        cout << "1. To input/modify input data" << endl;
        cout << "2. To cipher a message" << endl;
        cout << "3. To decipher a message" << endl;
        cout << "4. To perform a statistical analysis of the text." << endl;
        cout << "Press 0 to quit." << endl;
        cout << "Please choose: ";
        cin >> choice;

        if(choice==0) cout <<"Now quitting..";

        else if(choice==1) {
            if(flag_2==false) {
                cout << "Give input count: ";          //User Must input how many letters is in their word/phrase
                cin >> Letter_Amount;
                cout << "Please give text: ";            //User inputs their word/phrase
                for (int i=0; i<Letter_Amount; i++) {
                    cin >> word[i];               //Goes through the word array and stores the letters into an array value.
                }
                cout << endl;
            }

            else {                //This option is just if they want to change their word/phrase.
                cout << "Are you sure you want to modify the input?" << endl;
                cin >> Answer;
                if(Answer=='n') {
                    cout << "Returning to the main menu..\n\n";
                }
                else if(Answer=='y') {
                    cout << "Give new input count: ";
                    cin >> Letter_Amount;
                    cout << "Please give new text: ";
                    for (int i=0; i< Letter_Amount; i++) {
                        cin >> word[i];
                    }
                }
                else cout << "Please choose Y(es) or N(o).\n";
            }

            flag=true;
            flag_2=true;
        }

        else if(choice==2) {
            if(flag) {
                cout << "Please choose the number of shifts you want: ";      //User enters how many times to shift letters.
                cin >> shifts;
                for(int i=0; i<26; i++) {
                    if(i-shifts>=0) {
                        new_alphabet[i]=alphabet[i-shifts];       //This creates the shifted alphabet.
                    }
                    else {
                        new_alphabet[i]=alphabet[26+i-shifts];
                    }
                }
                for(int i=0; i<Letter_Amount; i++) {
                    for(int j=0; j<26; j++) {
                        if(word[i]==alphabet[j]) {
                            new_word[i]==new_alphabet[j];    //Supposed to change the letter from the alphabet to the shifted one.
                        }
                    }
                }
                cout << new_word;    //Then displays their ciphered word.
            }
            else cout << "Please use option 1 before using this one.\n\n";
        }

        else if(choice==3) {
            if(flag) {
                cout << "Option 3 is still under progress.\n\n";
            }
            else cout << "Plese use option 1 before using this one.\n\n";
        }

        else if(choice==4) {
            if(flag) {
                cout << " Option 4 is still under progress.\n\n" << endl;
            }
            else cout << "Please use option 1 before using this one.\n\n";
        }
    }
    while(choice!=0);
    return 0;
}

Your option 1 is asking for a character, not a word, which would require the user to press enter after each letter. I think you probably just want to remove that for loop and do that `cin` once, but not with an index on that char array.

As for the letter shifting, add 13 to the char (assuming caesar cipher is the same as ROT13) and then modulo with 25 and add 1 (there is no 0th letter of the alphabet).

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.