Caesar's Cipher Help

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.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
  #include <iostream>
#include <string>
#include <stdio.h>

using namespace 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;
}
   
closed account (48T7M4Gy)
for (int [i] = 0; [i] < MessageLength; [i] = [i] + 1)

for (int i = 0; i < MessageLength; i=i + 1) just might do the trick.
closed account (48T7M4Gy)
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.

http://www.cplusplus.com/doc/tutorial/arrays/
Last edited on
Topic archived. No new replies allowed.