A question in Saesar Cipher?

Hi,
I have written a very simple Saesar Cipher, but at the end of the program it crashes, why?
What do you suggest to improve it?
That's the code:

Sorry, I couldn't select code bracket at the time of posting it.

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

using namespace std;
string enc(string text,int key);
int main()
{

    string plainText;
    int key;

    cout<<"Enter a text to encrypt\n";
    cin>>plainText;
    cout<<"Enter a key to encrypt the text\n";
    cin>>key;
    enc(plainText,key);

    return 0;
}

    string enc(string text,int key){

    for(int i=0;i<text.length();i++){
        int s=text[i];
        s=s+key%26;
        cout<<char(s);

    }
    }
Last edited on
You forgot to return the encrypted string from the enc function.
Thanks Peter87.
Topic archived. No new replies allowed.