Help with Caesar Cipher Project for C#

Can someone please tell me why I am getting this error when I try to run my program, I followed the walkthrough video and I have the same code as him but I keep getting this error so I don’t know what I am doing wrong??


Program.cs(23,37): error CS0103: The name ‘newLetterPostion’ does not exist in the current context [/home/ccuser/workspace/csharp-caesar-cipher/CaesarCipher.csproj]

The build failed. Fix the build errors and run again.


using System;

namespace CaesarCipher
class Program
static void Main(string args)
char alphabet = new char {‘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’};

Console.WriteLine("Enter your secert message: ");
string input = Console.ReadLine();
char[] secretMessage = input.ToCharArray();

char[] encryptedMessage = new char[secretMessage.Length];

for(int i = 0; i < secretMessage.Length; i++)
  char letter = secretMessage[i];
  int letterPosition = Array.IndexOf(alphabet, letter);
  int newLetterPosition = letterPosition + 3;
  char letterEncoded = alphabet[newLetterPostion];
  encryptedMessage[i] = letterEncoded;
 string encodedString = String.Join("", encryptedMessage);
 Console.WriteLine($"Your encoded message is: {encodedString}");


newLetterPosition or newLetterPostion? One of those looks like a typo…

Ah thank you! I had been staring at the code too long I couldn’t see that typo! Thanks so much!!

1 Like

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.