HELP ME SIMPLE PROGRAMMING PROBLEM FOR EXPERT PROGRAMMERS

Problem
Write a program that will encode/decode any message based on the given secret instructions.

Input
The input shall be composed of 3 parts: A string, maximum length of 255 characters) in a single input line (i.e., terminated by the end-of-line or carriage return) representing the message to be encoded or decoded, A single character identifying the operation to be performed–‘E’ for encode or ‘D’ for decode, and An integer giving the number of columns to be (or that was) used for encoding called the key.

Output
The program shall display the encoded/decoded message. Since the algorithm fails if a sequence of spaces, at least as long as the key, is formed at, and subsequently deleted from, the end of the last column, replace spaces by periods in the output.
Input Validation
None.

Sample Runs

Enter the message: meet me in the park tonight at seven.
(E)ncode or (D)ecode? E
Enter number of columns (key): 5
Encoded message reads: mm.pth.neetaots.e.hrn.e.tiekiav..n..gte.

Enter the message: mm.pth.neetaots.e.hrn.e.tiekiav..n..gte.
(E)ncode or (D)ecode? D
Enter number of columns (key): 5
Decoded message reads: meet.me.in.the.park.tonight.at.seven....

Enter the message: TGDHEEE.D.H.SA.ES.C..RB.EE.TE..N.M..ED.SE.SC.AO.
(E)ncode or (D)ecode? D
Enter number of columns (key): 16
Decoded message reads: THE.SECRET.MESSAGE.HAS.BEEN.DECODED...........
We're not a homework service. Nobody is going to write this program for you.

If you have a question about the problem, ask it. If you need help, tell us what you need help with.
Show us what have you done so far.
What is your approach to the problem?
Where does the difficulty occur for you?

No one will do this for you. We are here to help you correct your code, and not write it for you.

Good luck.
I have the same problem. How can I arrange the text I will input into columns of five? Think it includes using array. But I'm not getting anywhere. HELP PLEASE.
THIS IS WHAT I HAVE SO FAR. :(



#include <iostream>
#include <string>
using namespace std;
int main()
{
string str1;
char option;

cout<<"Enter the message: "<<endl;
cin>>str1;
cout<<"(E)ncode or (D)ecode?"<<endl;
cin>>option;

switch(option)
{
case 'D':
cout<<"Hi"<<endl;
break;
// Still haven't done the program for Decode
case 'E':
cout<<"Hello"<<endl;
break;
// Still haven't done the program for Encode
default:
cout<< "The option is invalid.";
}

return 0;

}
Topic archived. No new replies allowed.