Hello
I have some trouble interpreting a string and I hope you can help me.
I have to convert a string, or a word in a number. Like five hundred fifty in 550. I dont know exactly how to do it.
I was thinking to try to analize each word, but this seems like a huge code. Or i was thinking that maybe you can check in a table, but then the table should be huge(numbers should go up to millions)
Is there a smarter way? What do you suggest?
Thank you very much

You are right to assume that there will be some code to write but its not that much. If you are going from a five hundred and fifty to 550 needs 3 tables. If you can use the STL than using a map you would be a great way to go. If you cant use The STL then it gets a little more complicated but not much. Let Me know if you can use STL and I can help you Figure out how to code this.

Hi Nathan,
Thank you very much for answering.
I don't know what is STL. I just read now that it's a sort of container, convept that I'm not very familiar.
If u know another way to do it and u can explain me I would be grateful, if not tell I will start reading what is a container STL :)

Alright. I would suggest using two arrays then. the first array would be of type char[][] and the second array would be of type int[]. the first array you would populate with all of the cases that you are going to encounter. start it with "one" then "two" and keep going to "nine". then you will need to add "ten" through "ninety". after that you just have to "hundred", "thousand" and so on. with the integer array you would populate it the same way but you would use the actual number. with those two arrays you can then run through the string and match a word in the string to one of the words in the char[] and then you can use the index you found the word in to find the decimal value in the integer array.

The other possibility, by using the STL container, you create an associative container, where the key is the string and the values is the representative number?

I have only one question. Why is the char array bidimmensional?

First yes you would make an associative container. second the reason i made it char[][] is so that you can store all of the words in one array. if it was just char[] you could have only one word. like char temp[] = "five"; . having it as char[][] you can do char temp[3][20] = {"one", "two", "three"}; . the first part is for how many words you need and the second part is for the size for each word.

Ok. Now I understood.
Thank you very much. i will let you know how it works :)

This question has already been answered. Start a new discussion instead.