|
-
May 2nd, 2008, 11:39 AM
#1
Thread Starter
Member
[2005] Concatenate variable as char
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?
-
May 2nd, 2008, 12:05 PM
#2
Re: [2005] Concatenate variable as char
I'm not sure I understand...
Do you need to make:
100 = ***
58585 = *****
-
May 2nd, 2008, 12:09 PM
#3
Re: [2005] Concatenate variable as char
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.
-
May 2nd, 2008, 01:56 PM
#4
Thread Starter
Member
Re: [2005] Concatenate variable as char
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.
-
May 2nd, 2008, 01:58 PM
#5
Thread Starter
Member
Re: [2005] Concatenate variable as char
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
-
May 2nd, 2008, 03:02 PM
#6
Re: [2005] Concatenate variable as char
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.
-
May 2nd, 2008, 03:26 PM
#7
Re: [2005] Concatenate variable as char
Here's another hint... you can do this to make your asterisks:
Code:
Dim strS As String = String.Empty.PadRight(10, "*"c)
Will produce: **********
(10 asterisks)
-
May 2nd, 2008, 03:34 PM
#8
Re: [2005] Concatenate variable as char
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 ***************
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|