Nov 28, 2012 at 7:00pm UTC
As a part of my coursework, I need to substitute digits in an array to their English equivalent .
For eg if my array stores "My roll no. is 1 and my rank is 3"
I want it to store "My roll no. is one and my rank is three"
Nov 28, 2012 at 7:16pm UTC
You could create an array of strings where each element contains its number in English. Then just go through the loop and swap any numbers for what is in the array at that element. Do you just need to substitute for 0-9, or more than that?
Nov 28, 2012 at 8:21pm UTC
This is a part of building a vigenere cipher.
So, in the message the user inputs, I need to convert the digits to their English equivalent and keep rest of the message intact.
Nov 28, 2012 at 10:55pm UTC
1 2 3 4 5 6
string english_words[] = { "zero" , "one" , "two" , "three" , "four" // etc }
int my_number = 3;
cout << english_words[my_number] << endl; // outputs "three"
This code is not complete, but it shows off the required structures required to complete your task. Some other methods to look up.
isAlpha(), isDigit(). What happens if the number is above 9?
and:
http://www.cplusplus.com/forum/articles/1295/
Last edited on Nov 28, 2012 at 10:56pm UTC
Nov 28, 2012 at 11:25pm UTC
Cheers!
Makes sense to me now! :)
I shall alter this to fit into my code.
Thanks!
And we can enter digits into the message from (0 to 9)
Nov 28, 2012 at 11:36pm UTC
one silly doubt
if i use char english_words[]= {"zero", "one","two",...etc}
then why do i get an error?
Nov 29, 2012 at 8:48am UTC
Because that's an array of characters, not an array of arrays of characters.
Use:
const char *english_words[] = {"zero" , "one" , "two" };