0

c# 42.2 cant pass hidden testcase

I can't figure out where I'm wrong, all the cases go through, but one always gives an error. I tried to do enumeration both through if / else and through switch namespace SoloLearn { class Program { static void Main(string[] args) { string[] games = { "Alien Shooter", "Tic Tac Toe", "Snake", "Puzzle", "Football" }; //введите код сюда int game = Convert.ToInt32(Console.ReadLine()); if( game == 0) Console.WriteLine(games[0]); else if (game == 1) Console.WriteLine(games[1]); else if (game == 2) Console.WriteLine(games[2]); else if (game == 3) Console.WriteLine(games[3]); else if (game == 4) Console.WriteLine(games[4]); else if (game == 5) Console.WriteLine(games[5]); else Console.WriteLine("Invalid number"); } } }

2nd Jul 2021, 12:22 AM
Anton Prozin
Anton Prozin - avatar
1 Réponse
+ 5
Why do you have an else if for game == 5 if there are only 5 elements in the array (0-4 indices)?
2nd Jul 2021, 1:15 AM
ChaoticDawg
ChaoticDawg - avatar