Black Windows console window prompting for a number between 1 and 10 for Roman numerals, with an error response to the input 11.

My Roman numeral program knew exactly what to say to an input of 11: โ€˜Jolly joker, thatโ€™s not a number between 1 and 10โ€ฆโ€™

Ohhh those Romans! With so many Ifs and ElseIfs it feels like Iโ€™m typing in circles, but hey! My code worked for a few of the examples, even if it wasnโ€™t the same as the listed solution. There are many ways to do the same thing, and I honestly think mine was more efficient and answered the question betterโ€ฆ which is odd, given they wrote both the question and the answer!

But thatโ€™s fine. As long as I can continue to insert Hoganโ€™s Heroes catchphrases and Pentium FDIV references into my code, the world is a better place.

        '3. Write a program that accepts a number from 1 to 100. For multiples of three print โ€œFizzโ€ instead of the number And for the multiples of five print โ€œBuzzโ€. For numbers which are multiples of both three And five print โ€œFizzBuzzโ€.
        Dim num1 As Integer

        Console.WriteLine("Enter a number between 1 and 100")
        num1 = Console.ReadLine()

        If num1 > 100 Or num1 < 1 Then
            Console.WriteLine("Your number is outside the parameters! Between 1 - 100 inclusive please.")
        ElseIf (num1 Mod 5 = 0) And (num1 Mod 3 = 0) Then
            Console.WriteLine("FizzBuzz")
        ElseIf num1 Mod 3 = 0 Then
            Console.WriteLine("Fizz")
        ElseIf num1 Mod 5 = 0 Then
            Console.WriteLine("Buzz")
        Else
            Console.WriteLine("Your number neither fizzes nor buzzes!")
        End If
        Console.ReadLine()

Pretty neat if you ask me. One catch: for a number divisible by neither three nor five, the final Else prints my joke rather than the number.

And Iโ€™ve learnt why 0.5 can become 0 when converting to an Integer in Visual Basic. Its integer conversion uses round-to-nearest-even when the fractional part is exactly .5:

  • 0.5 becomes 0
  • 1.5 becomes 2
  • 2.5 also becomes 2

So my conclusion that 0.00 must therefore round to -1 was, surprisingly, not how numbers work. Apparently the computer knew more mathematics than I did.

Sources