• Home
  • Textbooks
  • Microsoft Visual Basic Programs to Accompany Programming Logic and Design
  • Writing Programs that Make Decisions

Microsoft Visual Basic Programs to Accompany Programming Logic and Design

Jo Ann Smith

Chapter 4

Writing Programs that Make Decisions - all with Video Answers

Educators


Section 1

Understanding If Statements

Problem 1

In this exercise, you use what you have learned about writing If statements. Study the following code and then answer Questions 1-4.
```
' VotingAge.vb - This program determines if a person
' is eligible to vote.
Option Explicit On
Option Strict On
Module VotingAge
Sub Main()
' Work done in the housekeeping() procedure
Dim myAge As Integer = 19
Dim ableToVote As String = "Yes"
Const VOTING_AGE As Integer = 18
' Work done in the detailLoop() procedure
If myAge < VOTING_AGE Then
ableToVote = "No"
End If
' Work done in the endOfJob() procedure
System.Console.WriteLine("My Age: " & myAge)
System.Console.WriteLine("Able To Vote: " & _
ableToVote)
End Sub
End Module
```
What is the exact output when this program executes?
$\qquad$
$\qquad$

Check back soon!

Problem 2

In this exercise, you use what you have learned about writing If statements. Study the following code and then answer Questions 1-4.
```
' VotingAge.vb - This program determines if a person
' is eligible to vote.
Option Explicit On
Option Strict On
Module VotingAge
Sub Main()
' Work done in the housekeeping() procedure
Dim myAge As Integer = 19
Dim ableToVote As String = "Yes"
Const VOTING_AGE As Integer = 18
' Work done in the detailLoop() procedure
If myAge < VOTING_AGE Then
ableToVote = "No"
End If
' Work done in the endOfJob() procedure
System.Console.WriteLine("My Age: " & myAge)
System.Console.WriteLine("Able To Vote: " & _
ableToVote)
End Sub
End Module
```

What is the exact output if the value of myAge is changed to 15 ?
$\qquad$
$\qquad$

Check back soon!

Problem 3

In this exercise, you use what you have learned about writing If statements. Study the following code and then answer Questions 1-4.
```
' VotingAge.vb - This program determines if a person
' is eligible to vote.
Option Explicit On
Option Strict On
Module VotingAge
Sub Main()
' Work done in the housekeeping() procedure
Dim myAge As Integer = 19
Dim ableToVote As String = "Yes"
Const VOTING_AGE As Integer = 18
' Work done in the detailLoop() procedure
If myAge < VOTING_AGE Then
ableToVote = "No"
End If
' Work done in the endOfJob() procedure
System.Console.WriteLine("My Age: " & myAge)
System.Console.WriteLine("Able To Vote: " & _
ableToVote)
End Sub
End Module
```

What is the exact output if the expression in the If statement is changed to myAge $<=$ VOTING_AGE? $\qquad$
$\qquad$

Check back soon!

Problem 4

In this exercise, you use what you have learned about writing If statements. Study the following code and then answer Questions 1-4.
```
' VotingAge.vb - This program determines if a person
' is eligible to vote.
Option Explicit On
Option Strict On
Module VotingAge
Sub Main()
' Work done in the housekeeping() procedure
Dim myAge As Integer = 19
Dim ableToVote As String = "Yes"
Const VOTING_AGE As Integer = 18
' Work done in the detailLoop() procedure
If myAge < VOTING_AGE Then
ableToVote = "No"
End If
' Work done in the endOfJob() procedure
System.Console.WriteLine("My Age: " & myAge)
System.Console.WriteLine("Able To Vote: " & _
ableToVote)
End Sub
End Module
```

What is the exact output if the variable named ableToVote is initialized with the value "No" rather than the value "Yes"? $\qquad$

Check back soon!