Suppose a number is used in calculations throughout a program and must be changed every few months. What benefit is there to using a named constant to represent the number?
List and explain two Visual Basic selection statements. Provide at least one original example for each statement you list.
Benefits of using a named constant:
The value cannot be changed anywhere in the programming code.
It is easier to make widespread changes anywhere in the codes.
Code looks very neat and memory consumption is reduced.
VB selection statements:
1) If statement
Module decisions
Sub Main()
'local variable definition '
Dim num As Integer = 10
' check the boolean condition using if statement
If (num >=0) Then
' if condition is true then print the following
Console.WriteLine("Number is greater than or equal to zero")
Else
' if condition is false then print the following
Console.WriteLine("NUmber is less than zero")
Console.ReadLine()
End Sub
End Module
2) Switch statement
Module decisions
Sub Main()
'local variable definition
Dim grade As Char
gradeSystem = "C"
Select gradeSystem
Case "A"
Console.WriteLine("Superb perfomance!")
Case "B", "C"
Console.WriteLine("Well done this great work")
Case "D"
Console.WriteLine("You have passed")
Case "F"
Console.WriteLine("PLease try again")
Case Else
Console.WriteLine("You have entered an invalid grade ")
End Select
Console.WriteLine("Your grade is {0}", grade)
Console.ReadLine()
End Sub
End Module
Please rate it if the above solution helps you in any way or if you have any concerns comment it, I will help you through again.
Suppose a number is used in calculations throughout a program and must be changed every few...