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;
}