Caesars Cipher

Hi,

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.

Thanks

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
#include <iostream>


#include <string> 


using namespace 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.

Thank you, didn't really understand it but I have got the jist of it, thanks again.
Topic archived. No new replies allowed.