Substitute digits in an array for their English written equivalent

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"
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?
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.
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
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)
one silly doubt
if i use char english_words[]= {"zero", "one","two",...etc}

then why do i get an error?
Because that's an array of characters, not an array of arrays of characters.
Use:
const char *english_words[] = {"zero", "one", "two"};
Thanks! :)
Topic archived. No new replies allowed.