Ask Experts Questions for FREE Help !
Ask
    NonComputerNerd's Avatar
    NonComputerNerd Posts: 1, Reputation: 1
    New Member
     
    #1

    Sep 13, 2008, 02:37 PM
    If then statement using relationship operators
    Hi everyone,

    I'm trying to create a console application where a user enters 5 numbers and then the application gives them back the smallest and the largest number. However, I can't get my code to work. Here is what I have so far.

    Thank you to anyone that can help.

    Module Module1

    Sub Main()

    Dim number1 As Integer
    Dim number2 As Integer
    Dim number3 As Integer
    Dim number4 As Integer
    Dim number5 As Integer

    Console.Write("Please enter the first number: ")
    number1 = Console.ReadLine

    Console.Write("Please enter the second number: ")
    number2 = Console.ReadLine

    Console.Write("Please enter the third number: ")
    number3 = Console.ReadLine

    Console.Write("Please enter the fourth number: ")
    number4 = Console.ReadLine

    Console.Write("Please enter the fifth and final number: ")
    number5 = Console.ReadLine

    If number1 < number2 And number3 And number4 And number5 Then
    Console.WriteLine(number1 & " is the smallest number!")
    End If

    If number1 > number2 And number3 And number4 And number5 Then
    Console.WriteLine(number1 & " is the largest number!")
    End If

    If number2 < number1 And number3 And number4 And number5 Then
    Console.WriteLine(number2 & " is the smallest number!")
    End If

    If number2 > number1 And number3 And number4 And number5 Then
    Console.WriteLine(number2 & " is the largest number!")
    End If

    If number3 < number1 And number2 And number4 And number5 Then
    Console.WriteLine(number3 & " is the smallest number!")
    End If

    If number3 > number1 And number2 And number4 And number5 Then
    Console.WriteLine(number3 & " is the largest number!")
    End If

    If number4 < number1 And number2 And number3 And number5 Then
    Console.WriteLine(number4 & " is the smallest number!")
    End If

    If number4 > number1 And number2 And number3 And number5 Then
    Console.WriteLine(number4 & " is the largest number!")
    End If

    If number5 < number1 And number2 And number3 And number4 Then
    Console.WriteLine(number5 & " is the smallest number!")
    End If

    If number5 > number1 And number2 And number3 And number4 Then
    Console.WriteLine(number5 & " is the largest number!")
    End If

    Console.Read()

    End Sub

    End Module
    KingsX's Avatar
    KingsX Posts: 231, Reputation: 10
    Full Member
     
    #2

    Sep 21, 2008, 12:49 PM
    Its been a while since I've looked at VB, but I'd do this slightly different. I'd create a container variable to hold the highest number (or smallest). For example, create a variable x as integer. Then do your if statements like this (pseudo code)

    if number1 > number2 then x = number1 else x = number2

    if number3 > x then x = number3

    if number4 > x then x = number4

    if number5 > x then x = number5

    etc, etc. This way you always put the highest number into x, and then display x. Same would work in reverse for smallest number. You could even do smallest at the same time, by creating y.

    Late reply, but I hope I help.

Not your question? Ask your question View similar questions

 

Question Tools Search this Question
Search this Question:

Advanced Search

Add your answer here.


Check out some similar questions!

Multiple-step income statement in good form and retained earnings statement [ 1 Answers ]

Hi I would like someone to check to see if I did this correctly, if I did not then please help. Thanks The Problem is: The following pretax amounts pertain to River Corp. for the year ended December 31, 2008. Sales... $400,000 Operating Expenses... 84,000 Extraordinary gain... 30,000...

Relationship between Balance sheet and income statement [ 1 Answers ]

I just need to know the company performance by make a fixed relation ship between balance sheet and income statement

Income statement, owners equity statement and balance sheet [ 6 Answers ]

Les Fleurs, a boutique in Paris, France, had the following accounts in its accounting records at December 31, 20X2 (amounts in Euros, denoted as "E") Purchases………………... E250,000 Freight In……………… E8,000 Sales discounts…………. 4,000 Purchase returns…….. 7,000 Inventory Sales…………………. ...

Operators Manual [ 2 Answers ]

I need an operating manual for a GE range that is in the house I just bought. I need help setting the temp for the oven. I push the button for bake, then try to set the temp. The temp jumps from 170 to 550. If you can tell me what the procedure is that would be fine. Otherwise, please tell me...


View more questions Search