Ads 468x60px

Tuesday, 1 August 2017

How to Make a FizzBuzz Program in Visual Basic

Fizz-buzz happens to be one of the most simple programs that man has ever come up with. But, you'll be surprised to know just how significant it is when determining the true capabilities of a programmer. 

The "Fizz-Buzz Test" is a modern-day interview question, originally designed to distinguish 99.5% of programming job candidates who struggle with programming even the most basic pieces of code. Candidates are asked to write a program that prints a list of the numbers, one to a hundred, but with every multiple of 3 replaced with "Fizz" and every multiple of 5 replaced with "Buzz". For numbers that are multiples of both 3 and 5 (e.g the number 15), the program should display "FizzBuzz".

I have to admit, this is a pretty simple task but the tricky thing about this is that there are endless ways to accomplish it. The internet is presently overflowing with alternate solutions to the Fizz-Buzz Test and people are coming up with even more complex versions of it.

I decided to design my own version of the Fizz-Buzz program in Visual Basic to determine which kind of programming mindset I possess.

Here's my code:
Module Module1
    Sub Main()
        Dim rem3 As Integer
        Dim rem5 As Integer
        For count = 1 To 100
            rem3 = count Mod 3
            rem5 = count Mod 5
            If rem3 = 0 And rem5 = 0 Then
            ElseIf rem3 = 0 And rem5 > 0 Then
            ElseIf rem5 = 0 And rem3 > 0 Then
            Else : Console.WriteLine(count)
            End If
    End Sub
End Module
If you've found a simpler way to carry out this task, feel free to paste your code into the comment section below.


Post a Comment