Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. Order Help!

Order Help!

Scheduled Pinned Locked Moved Visual Basic
questiondatabaseregexhelp
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • U Offline
    U Offline
    User 10694570
    wrote on last edited by
    #1

    Again, I have a question on my homework this week. When I run my code, it doesn't list the races/results in order. What am I doing wrong?

    Dim chevy(8) As Decimal
    Dim ford(8) As Decimal
    Dim chevyCount As Integer = 0
    Dim fordCount As Integer = 0
    Dim index As Integer = 0

        For index = 0 To 7
            Console.WriteLine("Enter Chevy " & (index + 1) & " : ")
            chevy(index) = Console.ReadLine()
        Next
    
        Console.ReadLine()
    
        For index = 0 To 7
            Console.WriteLine("Enter Ford " & (index + 1) & " : ")
            ford(index) = Console.ReadLine()
        Next
    
        Console.ReadLine()
    
        For index = 0 To 7
            If (chevy(index) < ford(index)) Then
                chevyCount = chevyCount + 1
                Console.WriteLine("Chevy won by " & ford(index) - chevy(index) & " . ")
                Console.WriteLine("Chevy has won " & chevyCount & " races.")
            End If
        Next
        For index = 0 To 7
            If (chevy(index) > ford(index)) Then
                fordCount = fordCount + 1
                Console.WriteLine("Ford won by " & chevy(index) - ford(index) & " . ")
                Console.WriteLine("Ford has won " & fordCount & " races.")
            End If
        Next
    
        For index = 0 To 7
            If (chevy(index) = ford(index)) Then
                chevyCount = fordCount
                Console.WriteLine("This race was a tie!")
            End If
        Next
    
        Console.ReadLine()
    
        If chevyCount > fordCount Then
            Console.WriteLine("Chevy wins the match!")
        Else
            Console.WriteLine("Ford wins the match!")
        End If
    
        Console.ReadLine()
    
    End Sub
    
    L P 2 Replies Last reply
    0
    • U User 10694570

      Again, I have a question on my homework this week. When I run my code, it doesn't list the races/results in order. What am I doing wrong?

      Dim chevy(8) As Decimal
      Dim ford(8) As Decimal
      Dim chevyCount As Integer = 0
      Dim fordCount As Integer = 0
      Dim index As Integer = 0

          For index = 0 To 7
              Console.WriteLine("Enter Chevy " & (index + 1) & " : ")
              chevy(index) = Console.ReadLine()
          Next
      
          Console.ReadLine()
      
          For index = 0 To 7
              Console.WriteLine("Enter Ford " & (index + 1) & " : ")
              ford(index) = Console.ReadLine()
          Next
      
          Console.ReadLine()
      
          For index = 0 To 7
              If (chevy(index) < ford(index)) Then
                  chevyCount = chevyCount + 1
                  Console.WriteLine("Chevy won by " & ford(index) - chevy(index) & " . ")
                  Console.WriteLine("Chevy has won " & chevyCount & " races.")
              End If
          Next
          For index = 0 To 7
              If (chevy(index) > ford(index)) Then
                  fordCount = fordCount + 1
                  Console.WriteLine("Ford won by " & chevy(index) - ford(index) & " . ")
                  Console.WriteLine("Ford has won " & fordCount & " races.")
              End If
          Next
      
          For index = 0 To 7
              If (chevy(index) = ford(index)) Then
                  chevyCount = fordCount
                  Console.WriteLine("This race was a tie!")
              End If
          Next
      
          Console.ReadLine()
      
          If chevyCount > fordCount Then
              Console.WriteLine("Chevy wins the match!")
          Else
              Console.WriteLine("Ford wins the match!")
          End If
      
          Console.ReadLine()
      
      End Sub
      
      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      Member 10728667 wrote:

      it doesn't list the races/results in order

      You are going to explain what it is that you mean. Of course it lists them in order. It would really help us if you gave some idea of the input that you used, the output that you got and why the output is not what you expected it to be. Quite frankly without knowing what it is that you are trying to do here, it's really hard to figure out. But I can tell you that your code is doing exactly what you told it to do.

      1 Reply Last reply
      0
      • U User 10694570

        Again, I have a question on my homework this week. When I run my code, it doesn't list the races/results in order. What am I doing wrong?

        Dim chevy(8) As Decimal
        Dim ford(8) As Decimal
        Dim chevyCount As Integer = 0
        Dim fordCount As Integer = 0
        Dim index As Integer = 0

            For index = 0 To 7
                Console.WriteLine("Enter Chevy " & (index + 1) & " : ")
                chevy(index) = Console.ReadLine()
            Next
        
            Console.ReadLine()
        
            For index = 0 To 7
                Console.WriteLine("Enter Ford " & (index + 1) & " : ")
                ford(index) = Console.ReadLine()
            Next
        
            Console.ReadLine()
        
            For index = 0 To 7
                If (chevy(index) < ford(index)) Then
                    chevyCount = chevyCount + 1
                    Console.WriteLine("Chevy won by " & ford(index) - chevy(index) & " . ")
                    Console.WriteLine("Chevy has won " & chevyCount & " races.")
                End If
            Next
            For index = 0 To 7
                If (chevy(index) > ford(index)) Then
                    fordCount = fordCount + 1
                    Console.WriteLine("Ford won by " & chevy(index) - ford(index) & " . ")
                    Console.WriteLine("Ford has won " & fordCount & " races.")
                End If
            Next
        
            For index = 0 To 7
                If (chevy(index) = ford(index)) Then
                    chevyCount = fordCount
                    Console.WriteLine("This race was a tie!")
                End If
            Next
        
            Console.ReadLine()
        
            If chevyCount > fordCount Then
                Console.WriteLine("Chevy wins the match!")
            Else
                Console.WriteLine("Ford wins the match!")
            End If
        
            Console.ReadLine()
        
        End Sub
        
        P Offline
        P Offline
        Peter Leow
        wrote on last edited by
        #3

        I have taken a quick look: 1. change those

        Console.ReadLine()

        after every Next's to

        Console.WriteLine()

        2. There is a logical error here, find and fix it yourself:

        For index = 0 To 7
        If (chevy(index) < ford(index)) Then
        chevyCount = chevyCount + 1
        Console.WriteLine("Chevy won by " & ford(index) - chevy(index) & " . ")
        Console.WriteLine("Chevy has won " & chevyCount & " races.")
        End If
        Next

        3. You have missed out one more condition in:

        If chevyCount > fordCount Then
        Console.WriteLine("Chevy wins the match!")
        Else
        Console.WriteLine("Ford wins the match!")
        End If

        discover and add it yourself.

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups