I am stuck on my Caesar's Cipher program, I would appreciate if anyone would take time to look over the following program and see if any improvements could be made. But there is one error, it keeps on saying 'no such file or directory', I have asked a "programmer" (he thinks he is bill gates or something but he can't make a sprite move on scratch) but they haven't got round to help.
#include <iostream>
#include <string>
usingnamespace std;
char caesar( char );
int main()
{
string input;
do {
cout << "Type the message you want to code and then press enter" << endl;
cout << "Press enter again if you want to quit because you are boring" << endl;
getline(cin, input);
string output = "";
for(int x = 0; x < input.length(); x++)
{
output += caesar(input[x]);
}
cout << output << endl;
} while (!input.length() == 0);
}
char caesar( char c )
{
if( isalpha(c) )
{
c = toupper(c);
c = (((c-65)+13) % 26) + 65;
}
return c;
}
I am stuck on my Caesar's Cipher program, I would appreciate if anyone would take time to look over the following program and see if any improvements could be made.
You could make the code more flexible so that your encoding function would work with an arbitrary shift amount. You should avoid magic numbers. 'A' is more readable than 65.