Write a program to convert a three-digit number into the number of hundreds, tens and ones in the
number.
You must use integer division and mod in the calculations.
The input should be a three digit number and the output should be the number of hundreds, the number of tens and the number of ones.
The output will look like this: (Click to enlarge)
Here is the code:
'Write a program to convert a three-digit number into the number of hundreds, ‘tens and ones in the number. You must use integer division and mod in the ‘calculations. The input should be a threedigit number and the output should ‘be the number of hundreds, the number of tens and the number of ones.
Public Class frmSplitter
Private Sub btnSplit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSplit.Click
' Declare and associate variables
Dim Entry As Integer ' variable to hold Number entered
Dim Hundreds As Integer ' variable to hold Hundreds calculation result
Dim Tens As Integer ' variable to hold Tens calculation result
Dim Ones As Integer ' variable to hold Ones calculation result
' Assign values from user input and associate objects with variables
Entry = Val(txtEntry.Text)
Hundreds = Val(lblHundreds.Text)
Tens = Val(lblTens.Text)
Ones = Val(lblOnes.Text)
' Calculate the results
Hundreds = Entry - (Entry Mod 100)
Ones = Entry Mod 10
Tens = (Entry Mod 100) - Ones
' Display the results in the provided labels
lblHundreds.Text = Hundreds
lblTens.Text = Tens
lblOnes.Text = Ones
End Sub
Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click
' Exit the program and close the form
Me.Close()
End Sub
End Class
No comments:
Post a Comment