Ok, so basically the program runs, compiles and everything. But, after you run it, u will see the problem. When i run it it I cannot display the original entered information.

I am new to this and I have tried a few things, but everything I try seems to mess something else up.

Also, please don't bash me for using system("Pause"), it's the only way i know how to pause the program at the end.

#include<iostream.h>
#include<string.h>
#include<windows.h>

void CaesarEncrypt(char word[],int key,int size);
void GetWord(char word[],int &size);
void PrintArray(char array[],int n);

using namespace std;

int main()
{
	int key,size=-1;
	char word[100];
	cout << "Please enter a message to encrypt: ";
    GetWord(word,size);
	cout << "Please enter a shift distance: ";
	cin >> key;
	CaesarEncrypt(word,key,size);
	cout <<endl;
    cout << "The message that will be encrypted is:\n";
    //I cant figure out what to put here :(
    cout <<endl;
    cout << "The cipher text is:\n"; 				
	PrintArray(word,size);
    system("pause");
    return 0;
    
}

void CaesarEncrypt(char word[],int key,int size)
{
	for (int i=0;i<size;i++)
	{
		if (word[i]>64&&word[i]<91)
		{
			word[i]=(char)(((word[i]+key-65)%26)+65);
		}
		if (word[i]<123&&word[i]>96)
		{
			word[i]=(char)(((word[i]+key-95)%26)+95);
		}

	}
}

void CaesarDecrypt(char word[],int key,int size)
{
	for (int i=0;i<size;i++)
	{
		if (word[i]>64&&word[i]<91)
		{
			word[i]=(char)(((word[i]-key-65)%26)+65);
		}
		if (word[i]<123&&word[i]>96)
		{
			word[i]=(char)(((word[i]-key-95)%26)+95);
		}

	}
}

void GetWord(char word[],int &size)
{
	do
	{
		size++;
	word[size]=cin.get();
	}
	while (word[size]!='\n');
}

void PrintArray(char array[],int n)
{
	for (int i=0;i<n;i++)
	{
		cout << array[i];
	}
	cout <<endl;
}

The problem is that you only have 1 buffer word so as soon as you encrypt the string it contains you no longer have access to the original data.

What you need to do is have 2 buffers and then copy the input data to the second one and do the encryption on the second buffer. Then you will still have both buffers once you have done the encryption so will have both the clear and encrypted text.

You function GetWord is poorly written because it makes an unnecessary assumption about the entry value of size when it could simply initialize size itself.

You seem to be using C++ so you should consider using std::string rather than char arrays.

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.