writing some numbers...

weeshen

Member
Joined
Oct 1, 2006
Messages
13
Programming Experience
Beginner
Ok guys here my problem...its pretty simple but i can't think of a way to write it so simple...

the console app is supposed to take a number input by a user from 1 - 999 and output its written equivalent...example...52 from user would output fifty-two ... what is the simplest way of doing this? going all the way up to 999? any help would be excellent

i have started with the following code

Console.WriteLine("Enter a number between 1 and 999")
Dim x As Integer
x = CInt(Console.ReadLine)
Dim y As String 'y would be the output


 
I'd approach this by getting each digit by itsself first

VB.NET:
Dim intInput As Integer = 123
Dim intHundreds As Integer = Left(intInput, 1)
Dim intTens As Integer = Mid(intInput, 2, 1)
Dim intOnes As Integer = Right(intInput, 1)

Follow that up with select statement for each to convert the numbers:

pseudo:

Select Case intHundreds
Case 9
strHundreds = "Ninety"

Print the three strings your selected and your home(work) free ;-)
 
That answer does leave some questions open...

Do you have any more details? First question would be is the user input limited to certain number? (Always have three digits? No leading 0's?)
 
no leading zeros...i like the idea that you have and i thought about it...but what about teens?...everything from ten to twenty is hard to compensate for.
 
Nah, not really. Just an additional IF statement.

If intTens = 1 then
strTens = ""
end if

Select Case intOnes
Case 1
if intTens=1 then
strOnes="Eleven"
else
strOnes="One"
endif
end select

or something simliar.
 
ok...well that all makes sense...but here's the thing...i still need to be able to get the integer from the user in a console app...so i need to be able to read that code and basically translate it doing what you said.
 
Getting the integer from the user in console is quite easy:

VB.NET:
        Dim intInput As Integer
        Try
            intInput = CInt(Console.ReadLine())
            Console.WriteLine("Input Accepted")
        Catch strEx As Exception
            Console.WriteLine(strEx.Message)
        End Try

you would then break that intInput down as we've discussed above.
 
Back
Top