Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 3

Module Module1

' Title: tryVoting


' Author: Rabyan
' Date: 11/15/2020
' Version: 0.1
' Description: Voting for a new class captain

' Global Variables

Dim name(4) As String


Dim numC As Integer = 0
Dim vote As Integer = 0
Dim numS As Integer = 0

Sub Main()
' Local Variable

Dim vote As Integer = 0


Dim counter(4) As Integer
Dim swap As Boolean = True

' Subroutin of candidate


Call Candidate()
Console.Clear()

While numS < 1 Or numS > 30


Console.WriteLine("How many students are there?")
numS = Console.ReadLine()
End While

For y = 1 To numS
Console.Clear()
Call Onames()
Console.WriteLine("Please choose which candidate you would like to be
your new class captain.")
vote = Console.ReadLine()

' Add up the votes

Select Case vote


Case 1

counter(1) = counter(1) + 1

Case 2

counter(2) = counter(2) + 1

Case 3
counter(3) = counter(3) + 1

Case 4

counter(4) = counter(4) + 1

Case Else

Console.Clear()

' Bubble sort

While swap = True

swap = False

For z = 1 To 3

If counter(z) > counter(z + 1) Then


counter(0) = counter(z)
counter(z) = counter(z + 1)
swap = True

End If
Next z
End While
End Select
Next y

'Output the candidate with amount of vote

For x = 1 To numC

Console.WriteLine(name(x) & " has " & counter(x) & " votes")

Next x

Console.WriteLine("")

' Output if there is a new class captain or not

If counter(1) = counter(2) Then

Console.WriteLine("NO OVERALL WINNER")

Else

Console.WriteLine(name(1) & " is the NEW CLASS CAPTAIN")

End If
Console.ReadLine()
End Sub

' Ask for candidate name

Sub Candidate()

While numC < 2 Or numC > 4


Console.WriteLine("How many candidates are there?")
numC = Console.ReadLine()
End While

For i = 1 To numC

Do
Console.Clear()
Console.WriteLine("What is Candidate " & i & " Name")
Console.Write("Name - ")
name(i) = Console.ReadLine()
Loop Until name(i) <> ""

Next i

End Sub

'Output Candidate Names

Sub Onames()

For x = 1 To numC
Console.WriteLine("[" & x & "] - " & name(x))
Next x

End Sub

End Module

You might also like