Oh this is completly wrong, the idea is there but it's not that simple, do not check my contributions if you're doing this as a solo project and learning C++(look it up when you're finished)
What you need is to have a copy of the ASCII table first of all :
ASCII table I useThe basic idea is to add the offset onto the character. The problem is that using the declaration
char is going to be a problem since it holds a definite (if not one) letter. Your code converts the first letter.
*hint : use string.h*
Now for the encryption part :
My method was to use a different variable declared as int hence crypted
CODE
crypted = ch + offset;
cout<<char(crypted);
so I could use the original string in case I needed too or manipulate spaces (will be needed if the string includes it)
Now for the loop :
Use a for loop instead (will make the job easier) and use the
ch.length();. This value is the number of letters in the string (here ch). Make a separate variable and initialize to 0 then increment until the variable has reached ch.length();
CODE
for(a = 0; a != ch.length(); ++a)
//Encryption
Note : Once inside the loop, make sure you use
ch[a]; and not
ch; alone.
This way, the loop will process the whole string.
What if : x + 4 = | ?
You need to limit the alphabet inside the ASCII table :
The values you need are :
a = 97
z = 122
This part is more mathematical :
CODE
if(ch[a] + offset > 122)
crypted = ((ch[a] + offset) - 122) + 9;
The basic idea of this is to get the overvalue, substract 'z' then add the result to 'a'.
I hope I haven't talked too much and perhaps gave you a headache but the answer is there ^^
I could post the code right now but I'd rather like you understand what I said.