Professional Documents
Culture Documents
1. Body Mass Index (BMI) is a measure of health based on height and weight. It can be
calculated by taking your weight in kilograms and dividing it by the square of your height
in meters. The interpretation of BMI for people 20 years or older is as follows:
BMI Interpretation
BMI < 18.5 Underweight
18.5 ≤ BMI < 25.0 Normal
25.0 ≤ BMI < 30.0 Overweight
30.0 ≤ BMI Obese
Write a program that prompts the user to enter a weight in pounds and height in inches
and displays the BMI. Note that one pound is 0.45359237 kilograms and one inch is
0.0254 meters.
Imports System
Module BMICalculator
Sub Main()
Console.ReadLine()
End Sub
End Module
2. Suppose you want to develop a program to play lottery. The program randomly generates
a lottery of a two-digit number, prompts the user to enter a two-digit number, and
determines whether the user wins according to the following rules:
o If the user input matches the lottery number in the exact order, the award is KSh.
10,000.
o If all digits in the user input match all digits in the lottery number, the award is
KSh. 3,000.
o If one digit in the user input matches a digit in the lottery number, the award is
KSh. 1,000.
Write a program implementing this requirement.
Imports System
Module Program
Sub Main()
Console.ReadLine()
End Sub
End Module
3. Suppose you save $100 each month into a savings account with the annual interest rate
5%. So, the monthly interest rate is 0.05 / 12 = 0.00417. After the first month, the value
in the account becomes100 * (1 + 0.00417) = 100.417. After the second month, the value
in the account becomes (100 + 100.417) * (1 + 0.00417) = 201.252. After the third
month, the value in the account becomes (100 + 201.252) * (1 + 0.00417) = 302.507 and
so on. Write a program that prompts the user to enter an amount (e.g., 100), the annual
interest rate (e.g., 5), and the number of months (e.g., 6) and displays the amount in the
savings account after the given month.
Imports System
Module Program
Sub Main()
Console.WriteLine("Enter the initial amount:")
Dim amount As Double = Double.Parse(Console.ReadLine())
Console.WriteLine("The amount in the savings account after " & numMonths & " months is: " &
totalAmount.ToString("0.00"))
End Sub
End Module
4. Personal income tax is calculated based on filing status and taxable income earned as
shown in the table below. There are three filing statuses: single filers, married filing
jointly or qualified widow(er) and married filing separately. If you are, say, single with a
taxable income of $10,000, the first $8,350 is taxed at 10% and the other $1,650 is taxed
at 15%, so, your total tax is $1,082.50.
Write a program to compute personal income tax. Your program should prompt the user
to enter the filing status (Using select…case structure, enter 0 for single filers, 1 for
married filing jointly or qualified widow(er), 2 for married filing separately) and taxable
then compute personal income and display necessary details in a suitable format.
Imports System
Module PersonalIncomeTaxCalculator
Sub Main()
Console.WriteLine("Personal Income Tax Calculator")
Console.WriteLine("--------------------------------")
Console.WriteLine()
Console.WriteLine("Tax Details")
Console.WriteLine("Filing Status: " & filingStatus)
Console.WriteLine("Taxable Income: " & taxableIncome.ToString("C"))
Console.WriteLine("Tax Amount: " & tax.ToString("C"))
Console.ReadLine()
End Sub
End Module
|| ||
|| ||
|| || || || ||
|| ||
|| ||
Module MainModule
Sub Main()
DisplayPattern1()
Console.WriteLine()
DisplayPattern2()
Console.ReadLine()
End Sub
Sub DisplayPattern1()
For i As Integer = 1 To 5
For j As Integer = 1 To 5
If j = 3 And i <> 1 And i <> 5 Then
Console.Write("*")
Else
Console.Write("&")
End If
Next
Console.WriteLine()
Next
End Sub
Sub DisplayPattern2()
For i As Integer = 1 To 5
For j As Integer = 1 To 5
If i = 3 And (j = 3 Or j = 4) Then
Console.Write("||")
Else
Console.Write(" ")
End If
Next
Console.WriteLine()
Next
End Sub
End Module