Here\'s the question I have to answer. It\'s from ISBN 978-1-13-352608-7 on page
ID: 674677 • Letter: H
Question
Here's the question I have to answer. It's from ISBN 978-1-13-352608-7 on page 72. It's lab 4.5
In this lab, you complete a partially written Visual Basic program for an airline that offers a 20% discount to passengers who are 7 years old or younger and the same discount to passengers who are 65 years old or older. The program should request a passengers name and age, and the print whether the passenger is eligible or not eligible for a dicount.
Here is the code given and below that are the steps to follow in the book.
' Airline.vb - This program determines if an airline passenger is
' eligible for a 20% discount.
Option Explicit On
Option Strict On
Module Airline
Sub Main()
Dim passengerName As String = "" ' Passenger's name
Dim ageString As String = "" ' String version of passenger's age
Dim passengerAge As Integer = 0 ' Passenger's age
' This is the work done in the housekeeping() procedure
passengerName = InputBox$("Enter passenger's name: ")
ageString = InputBox$("Enter passenger's age: ")
' This is the work done in the detailLoop() procedure
passengerAge = Convert.ToInt32(ageString)
' Test to see if this customer is eligible for a 10% discount
End Sub
End Module
Here are the steps I have to follow.
1. Open the file named Airline.vb using Notepad or the text editor of your choice.
2. Variable have been declared and initialized for you, and the input statements have been written. Read them carefully before you proceed to the next step.
3. Design the logic, deciding whether to use AND or OR logic. Write the decision statement to identify when a discount should be offered and when a discount should not be offered.
4. Be sure to include output statements telling whether or not the customer is eligible for a dicount.
5. Compile the program.
6. Execute the program, entering the following as input:
a. Customer Name: Karen Matthews
Customer Age: 7
b. Customer Name: Robert Williams
Customer Age: 65
Explanation / Answer
Option Explicit On
Option Strict On
Module Airline
Sub Main()
Dim passengerName As String = "" ' Passenger's name
Dim ageString As String = "" ' String version of passenger's age
Dim passengerAge As Integer = 0 ' Passenger's age
' This is the work done in the housekeeping() procedure
passengerName = InputBox$("Enter passenger's name: ")
ageString = InputBox$("Enter passenger's age: ")
' This is the work done in the detailLoop() procedure
passengerAge = Convert.ToInt32(ageString)
' Test to see if this customer is eligible for a 10% discount
If passengerAge <= 7 Then
message = "You are eligible for 20% discount"
ElseIf passengerAge > 65 Then
message = "You are eligible for 20% discount"
Else
message = "You are not eligible for 20% discount"
End If
End Sub
End Module