+ 2
Help on number to text converter
I have been working on this off and on..and I keep getting stuck.. past a certain point the numbers don't convert quickly or I get an error.. I fix the error, but it still isn't right. I need some help as I am missing a piece... https://code.sololearn.com/cqo6xbl65xOk
8 Respostas
+ 1
You got to use the 'else if' statement. As of right now, your code is stopping at every 'if' statement. This is will get rid of the out of range exception. Thus allowing you to clean up any other display problems
[Edit2] you need to add an extra zero on line 35 right now its-
int value = number / 100000; and should be-
int value = number / 1000000;
+ 1
Laura
I was severely mistaken about the else if statements in my earlier comments.
I completely ignored the modulo operators and how there were being used, which is very clever.
I apologize to you for my hasty analysis of your code.
+ 1
ODLNT it's okay.. I did some more playing with it outside of sololearn.. I didn't post my latest update.... I don't think I can do this if it is greater than 9999... either without recursion based on research...not that there is anything wrong with that... or scrap it and try a different way....
+ 1
The bug I was referring is zeros, for example, the user enters 100200300123 before the fix the result was out of range exceptions.
Just to be clear I have no intention of usurping your project. I do find your project intriguing and challenging and I'm looking forward to what you will come up with.
0
I hope you don't mind, I took another shot at your code. I added nested if statement to the thousands, and millions.
https://code.sololearn.com/cVGuM39IxqUS/#cs
0
okay... I will take a look.
0
@ODLNT I checked your code.. I didn't see that bug. I'm wondering I left it at a double, why explicitly convert it to an int. this works, but the todo is for me to make it more efficient. I have some ideas which I have been thinking about...
0
okay i see the issue with why you explicitly converted back to an int. :)