Professional Documents
Culture Documents
AmeliaPBL1
AmeliaPBL1
Console.Write is a method used to write text to the console without adding a new
line character at the end of the text.
3. What does the word Dim stand for and what is it used for when writing a VB
program?
Dim is short for Dimension. It is a type of variable. You tell Visual Basic that you
are setting up a variable with the word.
5. Write a program that will ask the user to enter their name and country of
origin and display the information.
Module Program
'Write a program that will ask the user to enter their name and country of origin and display the information
Sub Main()
Dim name As String
Dim country As String
End Sub
End Module
6. Write a program to allow the user to input two integer values and then the
program print the results of adding, subtracting, multiplying, and dividing
among the two values.
Module Program
'Write a program to allow the user to input two integer values and then the program print the results of adding,
subtracting, multiplying, and dividing among the two values.
Sub Main()
Dim x As Integer
Dim y As Integer
End Sub
End Module
Sub Main()
Dim x, y As Integer
Console.WriteLine("Enter today's temperature in {0}", Chr(176) & "F")
x = Console.ReadLine()
y = (5 / 9) * (x - 32)
Console.WriteLine("Today's temperature in {0} is {1}", Chr(176) & "C", y)
Console.ReadLine()
End Sub
End Module
8. A farmer packs eggs into trays of 30 eggs in one tray. Calculate the number
trays of eggs for a given input of eggs.
Example if the farmer collects 100 eggs then there will be 3 trays of eggs.
Ask the user to input the number of eggs and the program will output the
number of trays of eggs.
Module Module1
' A farmer packs eggs into trays of 30 eggs in one tray. Calculate the number
trays of eggs for a given input of eggs.
' Example if the farmer collects 100 eggs then there will be 3 trays of eggs.
' Ask the user to input the number of eggs and the program will output the number
of trays of eggs.
Sub Main()
Dim x, y As Integer
Console.WriteLine("Please enter the number of eggs: ")
x = Console.ReadLine()
y = x / 30
Console.WriteLine("There are {0} number of trays of eggs.", y)
Console.ReadLine()
End Sub
End Module
9. Write a program to calculate the salary for a worker. The salary is calculated
based on the hours worked and the pay rate per hour.
Example, if the worker worked 40 hours and the rate per hour is RM10,
then the salary is RM400 ( 40 hours X RM10 ).
Write a program that will ask the user to input the number of hours worked
and the rate per hour. The program will then calculate and output the
salary for the worker
Module Module1
' Write a program to calculate the salary for a worker. The salary is calculated
based on the hours worked and the pay rate per hour.
' Example, if the worker worked 40 hours and the rate per hour is RM10, then the
salary is RM400 ( 40 hours X RM10 ).
Sub Main()
Dim Hours, Rate, x As Integer
Console.WriteLine("Enter how many hours worked: ")
Hours = Console.ReadLine()
Console.WriteLine("Enter the rate per hour in RM: ")
Rate = Console.ReadLine()
x = Hours * Rate
Console.WriteLine("The salary is RM{0}", x)
Console.ReadLine()
End Sub
End Module
10. A marathon runner records their time for a race in hours, minutes and
seconds.
An algorithm is shown below in structured English.
Write a program for the following algorithm.
Sub Main()
Dim hour, minute, seconds As Decimal
Console.WriteLine("Enter your hour: ")
hour = Console.ReadLine()
Console.WriteLine("Enter your minute: ")
minute = Console.ReadLine()
Console.WriteLine("Enter your seconds: ")
seconds = Console.ReadLine()
Console.WriteLine("Your race time in seconds is: {0}", (hour * 3600) + (minute
* 60) + seconds)
Console.ReadLine()
End Sub
End Module