For one of my programming classes, we're supposed to display an output as asterisks, with each asterisk representing the number 100. How do you set up a do while loop to convert the input number to an asterisk?
Printable View
For one of my programming classes, we're supposed to display an output as asterisks, with each asterisk representing the number 100. How do you set up a do while loop to convert the input number to an asterisk?
I'm not sure I understand...
Do you need to make:
100 = ***
58585 = *****
You will get the user's input probably from a textbox or a inputbox, which is a string, then convert it to an integer. Now divide this integer by 100 and you'll have the number of asterisks to display. Once you know how many asterisks are required, you create a string with that many asterisks and display it. There's no loop involved at all.
Here I'll type you exactly what it says to do.
Create an application that prompts the user to enter today's sales for five stores. The program should then display a simple bar graph comparing each store's sales. Create each bar in the bar graph by displaying a row of asterisks (*) in a list box. Each asterisk should represent $100 in sales.
here's what i have so far:
Private Sub btnDisplay_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles btnDisplay.Click
' Gather sales information and display a bar chart.
Dim intCount As Integer = 0 ' Loop counter
Dim decSales As Decimal ' To hold sales for each store
Dim strInput As String ' To get store information
' The following loop will get the sales amounts for each store.
Do While intCount <= 4
intCount += 1
strInput = InputBox("Enter the sales for store # " & _
intCount.ToString, "Sales Amount Needed")
If strInput <> "" Then
decSales = CDec(strInput) ' Store input in sales
Else
Exit Do
End If
strInput = "Store " & intCount & ":" & decSales.ToString()
lstChart.Items.Add(strInput)
Loop
End Sub
For each of the values entered, divide the number by 100 (whole result) and create a string with that many asterisks in it. Add to listbox.
Here's another hint... you can do this to make your asterisks:
Will produce: **********Code:Dim strS As String = String.Empty.PadRight(10, "*"c)
(10 asterisks)
Code:Dim testNums() As Decimal = {100.5D, 211, 312, 1000, 1510.45D}
Dim testAster As String
Debug.WriteLine("'Debug Output")
For x As Integer = 0 To testNums.Length - 1
testAster = String.Empty.PadRight(Convert.ToInt32(testNums(x) / 100), "*"c)
'or
'testAster = StrDup(Convert.ToInt32(testNums(x) / 100), "*"c)
Debug.WriteLine("'" & testNums(x) & " " & testAster)
Next
'Debug Output
'100.5 *
'211 **
'312 ***
'1000 **********
'1510.45 ***************