help with decrypt and encrypt

1. Write a function with the following prototype:
void toLowerCase( char [ ] );
The function receives a string as argument and converts all the upper-case letters in the string to lower-case. Any character in the string that is not in upper-case, e.g. lower-case or non-alphabet character will remain unchanged.
2. Write a function that decrypts the message. The function prototype is given below:
void decrypt( char msg[ ] );
3. Write a main function to test your functions in the following steps:
1. Get the original message: Today a Nobel laureate will visit SAU.
2. Call toLowerCase
3. Display the resulting message
4. Call encrypt
5. Display the resulting message
6. Call decrypt
7. Display the resulting message





#include <iostream>

using namespace std;
void encrypt (char []);

int main()
{
char msg []= "hello z";
encrypt (msg);
cout << msg << endl;
}

void encrypt (char msg []){
int key = 15;
int i = 0;
while (msg [i] != '\0'){
if (msg[i] <= 'z' && msg[i] >= 'a'){
if (msg[i] + key <= 'z'){
msg[i] = (char)(msg[i] + key);
}
else {
int d = msg [i] + key - 'z';
msg [i]= (char)'a' + d - 1;
}
}
i ++;
}
}
char mychars[10] = {'g','h','i','a','b','c','d','e','f', 'l'};

for(int i = 0; i < 10; i++) mychars[i] = toupper(mychars[i]);//sets to upper case

for(int i = 0; i < 10; i++) std::cout << mychars[i];
std::cout << '\n';
for(int i = 0; i < 10; i++) mychars[i] += 3; //encripts

for(int i = 0; i < 10; i++) std::cout << mychars[i];
std::cout << '\n';
for(int i = 0; i < 10; i++) mychars[i] -= 3; // decripts

for(int i = 0; i < 10; i++) std::cout << mychars[i];

return 0;
}


This is the program I have previously written... How can I write the new functions?

Topic archived. No new replies allowed.