0

I am really struggling trying to understand how to increment a message based off the input in a file. I have it all worked out to pass in each character individually to a function. I have thought through it and decided it would be easiest to read in and assign the letter it reads into an array then increase based off how many the "offset" is.

What I am trying to do is a Caesar Cipher. I have read in each character from a file which is the char character. I would now like to offset each character I have read in by that much based off the letter it was originally.

So A offset 0 is: A A offset 1 is: B

Here is what I have so far:

char rotate(char character, int offset) {

    char lowerAlphabet[26] = {'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'};

    bool isUpper(char character);
    bool isLower(char character);

    cout << character;
}

The final result would be the cout << character.

Any help is appreciated.

ForgedFire
  • 15
  • 4
  • Could you explain what you are trying to do in some other way? What does it mean to "increment a message"? Your "rotate" function as written basically does nothing useful. – Alex Oct 02 '17 at 03:17
  • Updated the original post. – ForgedFire Oct 02 '17 at 03:26
  • `bool isUpper(char character);` is a function prototype, not a function call. I strongly recommend refreshing your understanding of C++ syntax with [the help of a good book.](https://stackoverflow.com/questions/388242/the-definitive-c-book-guide-and-list) – user4581301 Oct 02 '17 at 04:19

1 Answers1

0
char rotate(char character, int offset)
{
    char cCharacter = character + offset;
    if (isLower(character))
        cCharacter = 'a' + cCharacter % ('z' - 'a' + 1);
    else
        cCharacter = 'A' + cCharacter % ('z' - 'a' + 1);

    cout << cCharacter;
    return cCharacter;
}
Alex
  • 111
  • 3