I'm new to the study of programming, in my opinion in this code everything is correct, but it does not work properly. Could you show me the reason. Thank you very much!!!
Task condition:
In one array the number of goals scored by the football team in each of the 20 games is recorded, in the other - the number of goals conceded in the same game. For each game, determine the verbal outcome of the game (win, lose or draw).
scoredGoals = Array.new(20) { rand(0...10) } #20 matches. scoredGoals
concededGoals = Array.new(20) { rand(-10...0) } #20 matches. concedeGoals
i = 0
while (i < 20)
if scoredGoals[i] == concededGoals[i]
puts "Friendship won";
elsif scoredGoals[i] < concededGoals[i]
puts "Defeat";
elsif scoredGoals[i] > concededGoals[i]
puts "Victory";
end
i = i + 1;
end
puts "==========================="
puts scoredGoals
puts "==========================="
puts concededGoals
The output shows "Victory" every time.
concededGoalsarray contains negative numbers. Any positive number will be larger than a negative number. Quick fix: userand(0...10)for both arrays.