In: Computer Science
Use Visual Basic Language
In this assignment you will need to create a program that will have both a “for statement” and an “if statement”. Your program will read 2 numbers from the input screen and it will determine which is the larger of the 2 numbers. It will do this 10 times. It will also keep track of both the largest and smallest numbers throughout the entire 10 times through the loop. An example of the program would be the first time through the loop; you input the number 10 and 50. The program would respond with 50 being the larger of the two. You next would input 100 and 75. The program would then respond with 100 being the larger of the two. Upon the 10th time through the loop the program would determine not only which number is the largest but also what was the largest number in the session and which was the smallest number in the session. In this example we only did two loops through the session but the correct answer at this point would be the largest number as 100 and the smallest as 10.
A few hints...
• Create variable
o Num1
o Num2
o Lownum
o Highnum
For loop will be 1 to 10
• If statements
If num1 > num2 then
Console.writeline(“Number 1 is larger ” & Num1)
o Else Console.writeline(“Number 2 is larger ” & Num2)
o End if
If statement to check high and low
If num1 > highnum then
Highnum = num1
o End if
If num1 < lownum then
Lownum = numn1
o End if
o Don’t forget num2
Application Name :VB_Numbers_ConsoleApp
Application Type :Console Application
Language used :VB
Module1.vb :
Module Module1 'VB Module
Sub Main() 'Main() procedure
'declaring variables
Dim num1 As Integer
Dim num2 As Integer
Dim lowNum As Integer
Dim highNum As Integer
'using for loop
For i = 1 To 10
'asking user two numbers
Console.Write("Enter numbers 1 : ")
'reading numbers
num1 = Integer.Parse(Console.ReadLine())
Console.Write("Enter numbers 2 : ")
num2 = Integer.Parse(Console.ReadLine())
'using If else checking numbers
If num1 > num2 Then
'when num1 is greater than num2 then
Console.WriteLine(“Number 1 is larger ” & num1)
If i = 1 Then 'this code snippet is used for high and low num
highNum = num1
lowNum = num2
End If
Else
'when num2 is greater than num1 then
Console.WriteLine(“Number 2 is larger ” & num2)
If i = 1 Then 'this code snippet is used for high and low num
highNum = num2
lowNum = num1
End If
End If
'checking number for high
If num1 > highNum Then
'when num1 is greater than highnum
highNum = num1
End If
'checking number for low
If num1 < lowNum Then
'when num1 is less than lowNum
lowNum = num1
End If
'checking number for high
If num2 > highNum Then
'when num2 is greater than highnum
highNum = num2
End If
'checking number for low
If num2 < lowNum Then
'when num2 is less than lowNum
lowNum = num2
End If
Next
'print High number
Console.WriteLine("highNum : " & highNum)
Console.Write("lowNum : " & lowNum) 'print low num
End Sub
End Module
======================================
Output :