Array help. IfThen help. I am new to programming

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • trav4
    New Member
    • Feb 2008
    • 1

    Array help. IfThen help. I am new to programming

    I have an assignment for school and I am new to programming. For the assignment I need to make a survey with at least 4 choices that uses 2 arrays. It must be done in a console application. How do I make it loop and count/store the responses until the user enters "N" at strAnswer=Conso le.readline? Where/what loop would I use?

    [code=vbnet]
    Module Module1

    Sub Main()
    Dim strAnswer As String
    Console.WriteLi ne("Do you want to answer survey")
    strAnswer = Console.ReadLin e()
    While Not strAnswer.ToUpp er.StartsWith(" N")
    Dim resp(3) As Integer
    Console.WriteLi ne("Pick a number between 1 and 4")
    resp(0) = Console.ReadLin e
    'declare response frequency array
    Dim frequency As Integer() = New Integer(4) {}
    ' count frequencies
    For answer As Integer = 0 To resp.GetUpperBo und(0)
    frequency(resp( answer)) += 1
    Next
    Console.WriteLi ne("Choices" & vbTab & "Frequency" )
    'display output
    For rating As Integer = 1 To frequency.GetUp perBound(0)
    Console.WriteLi ne(rating & vbTab & frequency(ratin g))
    Next
    Console.WriteLi ne("Do you want to answer survey")
    strAnswer = Console.ReadLin e()
    End While
    End Sub
    End Module[/code]
    Last edited by debasisdas; Feb 25 '08, 07:21 AM. Reason: added code= vbnet tags.
  • debasisdas
    Recognized Expert Expert
    • Dec 2006
    • 8119

    #2
    Question moved to .net forum.

    Comment

    Working...