I want to accept numbers from the user into an array and convert into corresponding alphabets. E.g 1 into A, 2 into B, and so on.
This is simple, but the problem is the user is supposed to enter the character # also which I want to display as it is in the output.
How can I do this ?
What type of array should be used - int or char?
Huch, I didn't think i had that much problems doing such a simple task...
Since you want to save it as Characters you should go for a char array (but in C++ you usually use std::string instead of char Arrays)
I don't know some things you want to accomplish or how you wanted to handle invalid input so i handeled it like this:
- When a user inputs a number between 1 and 26 the Number gets converted to a Capital Letter(A-Z), otherwise an exception will be thrown;
- If the input is not an integer, an exception will be thrown;
- If the exception is thrown, the current input will be ignored and replaced by '#'
(and the stream get's flushed because we want to read new data)
Thnx @gamer2015, but I feel I did not convey the question properly.
So here is the exact problem..
Chris has been sent secret coded messages from his associates. Given the encoding scheme and the message, print the actual message.
Encoding Scheme:
1. All letters are upper case.
2. A space is indicated by an underscore (_)
3. A number is preceded by the number symbol (#)
4. Each letter is converted as follows: A=1, B=2, C=3, etc.
Output:
All letters are upper case. The only position a space is to be output is where the underscore symbol (_) appears in the encoded message. The output is to be formatted exactly like that for the sample output given below.
Assumptions:
There is 1 space between each item on the data line.
Character set for the message is: {(A-Z) , (0-9) , _ , #} only.
Sample Input:
# 1 13 15 14 20 8 # 3 4 1 25 19
Sample Output:
1MONTH3DAYS (Number after # should be printed as it is !)