Hi,
I have an assignment at school to make a Caesar's Cipher, i can't get it to work because it keeps on saying that [i] is wrong in my code, i would love someone to have a look at this piece of code and try to fix it, thank you very much.
#include <iostream>
#include <string>
#include <stdio.h>
usingnamespace std;
int main ()
{
char Message, LetterBeingExamined, LetterBeingExaminedPlusOffset;
int Offset = 0;
int MessageLength = 0;
int ASCIICodeLetter[100];
Offset = 5;
cout << "Enter letter to be encrypted: ";
cin >> Message;
MessageLength = 1;
cout << "\nThe letter you would like to Encrypt is: " <<Message;
cout << "\n\nThe length of the Letter you want to Encrypt is " <<MessageLength << " byte(s) (including spaces).\n";
for (int [i] = 0; [i] < MessageLength; [i] = [i] + 1)
{
Message[i] = LetterBeingExamined;
ASCIICodeLetter[i] = (int) LetterBeingExamined;
}
if ((int(LetterBeingExamined) >= 65) && (int(LetterBeingExamined)<= 122))
{
LetterBeingExaminedPlusOffset = (int) LetterBeingExamined + Offset;
cout << "Value of letter plus offset"<< int(LetterBeingExaminedPlusOffset);
if (LetterBeingExaminedPlusOffset > 90)
{
cout <<"\nValue of letter plus offset is greater than 90.";
LetterBeingExaminedPlusOffset = LetterBeingExaminedPlusOffset - 26;
}
}
else
{
LetterBeingExaminedPlusOffset = int(LetterBeingExamined);
}
cout <<"\nValue of Encrypted Letter after subracting 26 (if necessary) is " << int(LetterBeingExaminedPlusOffset);
ASCIICodeLetter [i] = LetterBeingExaminedPlusOffset;
ASCIICodeLetter [i] = LetterBeingExaminedPlusOffset;
cout << "\nEncrypted letter is " << LetterBeingExaminedPlusOffset << ".\n";
return 0;
}
Also, you have a number of arrays you havent declared properly.
eg Message[i] comes out of the blue. It is an array element and yet you haven't declared the array.
You need something like char Message[1000] = {0]; to start off with, then you canrefer to the i-th element by Message[i]
You can't have an array element Message[x] and another (non-array) variable called Message too.