Odd or Even Problem

Posts 1–5 of 5 · Page 1 of 1
Odd or Even Problem
Heya guys.. i took a computer programming course at my school and here's our first homework.

My teacher gave us this code and for some reason i cnt figure it out why it keep saying "even".

Teachers Code:
Code:
input = textbox
if isNumeric(input)
	if(input mod 2 = 0)
		print:input is even
	elseif(input mod 2 = -1) or (input mod 2 = 1)
		print: input is odd
	else
		print: input is neither
else
	print:input is non-numeric
My Verson:
Code:
Dim Input As Long
        IsNumeric(Input)
        If Input Mod 2 = 0 Then
            MsgBox("Even")
        ElseIf Input Mod 2 = -1 Or Input Mod 2 = 1 Then
            MsgBox("Odd")
        Else
            MsgBox("Neither")
        End If
Help Please.
Code:
 Dim myNum As Long
        myNum = Val(TextBox1.Text)
        If myNum Mod 2 Then
            MsgBox("You've entered an odd number.")
        Else
            MsgBox("You've entered an even number.")
        End If
that works
I need the VB version of this code
Code:
input = textbox
if isNumeric(input)
	if(input mod 2 = 0)
		print:input is even
	elseif(input mod 2 = -1) or (input mod 2 = 1)
		print: input is odd
	else
		print: input is neither
else
	print:input is non-numeric
Your not declaring what input value is aka textbox1.text just declare what it is to fix it...

@Jerymiah94

maybe declare 0 as a neutral number in-case they try for some extra credit
Code:
If IsNumeric(TextBox1.Text) Then
    Dim value As Long = Long.Parse(TextBox1.Text)
    If value Mod 2 = 0 Then
        MsgBox("Even")
    ElseIf value Mod 2 = -1 OrElse value Mod 2 = 1 Then
        MsgBox("Odd")
    Else
        MsgBox("Neither")
    End If
Else
    MsgBox("Non-numeric")
End If
Posts 1–5 of 5 · Page 1 of 1

Post a Reply

Similar Threads

Tags for this Thread

None

Need help?