Order Help!
-
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 = 0For 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
-
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 = 0For 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
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.
-
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 = 0For 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
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
Next3. 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 Ifdiscover and add it yourself.