Question question about for next Nested Loops- Please help

mike888

New member
Joined
Jun 5, 2011
Messages
2
Programming Experience
Beginner
this is my first vb. and i have assignment and i have been trying for hours but i couldn't do it right . if anyone can help me please.

Hi, I have to create an application that prompts the user to enter today’s sales for five stores.
Create a loop to prompt for an amount for the first store using an inputbox and do not exit until you have good data. The inputs cannot be negative or greater than 5000, but may contain decimal values.
The program should then display a simple bar graph corresponding to the amount of sales using a row of asterisks (*) in a listbox. Each asterisk represents $100 in sales. Display the total of all the stores by looping this process for each store.

the program's gui should look:
39154884.jpg


"Build output string using concatenation to add “*” using For/Next loop "
"Use For/Next loop for processing stores"

i tried many times everytime there is something missing . "
i want Each asterisk represents $100 in sales.
and i don't want the inputbox exit until I have a good data.

Thanks to anyone in advance who can help me

VB.NET:
  Private Sub btnCalculate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCalculate.Click
        Dim intCount As Integer = 1
        Dim strInputs As String         'To hold user inputs
        Dim DblStoreSales As Double    'to Hold store's sales
        Dim intAsteriskValue As Integer = 100 '*.
        Dim intTotalAsterisk As Integer     ' The number of asterisks to display
        Dim strAsterisks As String
        Dim strOut As String = String.Empty
        Dim dblTotalSales As Double = 0


        For intCount = 1 To 5
            strInputs = InputBox("Enter Todays’s Sales for store " & intCount, "Store Sales")
            For intTotalAsterisk = 1 To intTotalAsterisk
                If Not Double.TryParse(strInputs, DblStoreSales) Then
                    MessageBox.Show("store Sales Must be Numeric", "Store Sales Error")
                ElseIf DblStoreSales < 0 Then
                ElseIf DblStoreSales > 5000 Then
                    MessageBox.Show("Store sales can not be less than 0 or Greater than 5000", "store sales Error")
                Else
                    dblTotalSales += DblStoreSales
                    intTotalAsterisk = CInt(Math.Round(DblStoreSales / intAsteriskValue))
                End If
                strAsterisks = "*"

                If intTotalAsterisk = 0 Then
                    strAsterisks = ""
                Else
                    strAsterisks = "*"
                    strOut = ("store " & intCount.ToString() & "  " & DblStoreSales.ToString("c") & ":" & strAsterisks)
                    lstSales.Items.Add(strOut)
                End If
               


            Next intTotalAsterisk

        Next
        lstSales.Items.Add("The total sales were " & dblTotalSales.ToString("N"))
    End Sub
End Class
 
Last edited:
Your second For statement will execute exactly once. You just assigned intTotalAsterisk to 1, effectively erasing the previous value. Maybe try a Do...Loop Until loop instead of a For loop.

The Do loop is more suited for what you are describing. It loops until a condition is met, in your case until the user enters valid input.

This should get you a start. If you have more problems, please state which part is not working...is the input box not asking for input multiple times...is the * count wrong...?
 
thank you so much

Your second For statement will execute exactly once. You just assigned intTotalAsterisk to 1, effectively erasing the previous value. Maybe try a Do...Loop Until loop instead of a For loop.

The Do loop is more suited for what you are describing. It loops until a condition is met, in your case until the user enters valid input.

This should get you a start. If you have more problems, please state which part is not working...is the input box not asking for input multiple times...is the * count wrong...?
thank you so much.
Do u know how can I do ( Each asterisk represents $100 in sales. ) by using for next loop

Thank you so much.
 
Back
Top