Hi everyone. The problem is:
"implement source to convert number into words. eg: if input is 454, result is four hundred fifty four.
I spent my entire noon and afternoon in this single problem and finally came up with the this code. Yet I feel that this is too long. Can anyone suggest a more concise code for the same problem.(please note that i only know concept of if,loop, and function.4 days into c++) My code is:
Also, when you get to arrays, consider rewriting using an array lookup. Here's a link to my old numbers-to-words challenge: http://www.cplusplus.com/forum/lounge/74394/
(for more ideas in the future)
hmm, very big codes. can it be done less than 100 lines!
Are you being smug about something, or just making an observation about the code in my link?
(Because you'll notice that all the code in my link does it in less than 100 lines, discounting commentary and the requirement of making a fully functioning program. Not to mention that everyone's examples are pretty robust about handling fairly large numbers.)
Re: compressing vertical whitespace:
if you write following way, it would be much shorter and easier to read:
1 2 3
if (tens_digit==7) cout<<" Seventy ";
if (tens_digit==8) cout<<" Eighty ";
if (tens_digit==9) cout<<" Ninty ";
+ 1
Using arrays to look stuff up would also do that, but it is still a good comment if not using arrays.
@duoas, latter. in fact previously i only glanced there, and it seemed little confusing seeing 100+ lines from experienceds (while OPs code will be under 100 if he formats as suggested, or even shorter if arrays are used.)
you are right, i didn't notice that nearly half of their length were comments.