Help with basic console application
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums
Results 1 to 4 of 4

Thread: Help with basic console application

Threaded View

  1. #1
    Join Date
    Oct 2012

    Help with basic console application


    I need a little help finishing a program for school - I missed class last week and am a little stuck with one of the request from the professor.

    I'm not sure about how to get the code to display invalid integer when you choose option 4 and you try to divide by 0 as of now it just displays nan = which i know is visual basic stating infinity. If you could point me in the right direction that would be great - as I want to get a + on this assignment.

    This is what i have so far.

    Thank You

    Module Module1
        Sub Main()
            'Store needed Variables
            Dim num1, num2 As Integer
            Dim opt1, opt2, opt3, opt4 As String
            Dim choice As Integer
            'Prompt user for 2 Integers
            Console.WriteLine("Please enter 2 numbers?")
            num1 = Console.ReadLine
            Console.WriteLine("Please enter 2nd number")
            num2 = Console.ReadLine
            Console.WriteLine("Please Select a following option:")
            Console.WriteLine("Option 1 = Add both integers")
            Console.WriteLine("Option 2 = Subtract 2nd integer from 1st integer")
            Console.WriteLine("Option 3 = Multiply Integers")
            Console.WriteLine("Option 4 = Divide 1st integer by 2nd integer")
            Console.WriteLine("What is your Choice?")
            choice = Console.ReadLine
            opt1 = num1 + num2
            opt2 = num1 - num2
            opt3 = num1 * num2
            opt4 = num1 / num2
            If choice = "1" Then
                Console.WriteLine("Option 1=" & opt1)
            ElseIf choice = "2" Then
                Console.WriteLine("Option 2=" & opt2)
            ElseIf choice = "3" Then
                Console.WriteLine("Option 3=" & opt3)
            ElseIf choice = "4" Then
           Console.WriteLine("Option 4=" & opt4)
            ElseIf choice = "4" And num1 <= 0 Or num2 <= 0 Then
                Console.WriteLine("Error Invalid Integer")
            Else : Console.WriteLine("Invalid Choice")
            End If
    Kind of stuck at the last part.
    Last edited by GremlinSA; October 27th, 2012 at 06:54 AM. Reason: added code tags

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Windows Mobile Development Center

Click Here to Expand Forum to Full Width

This is a survey!

HTML5 Development Center