This test case is hidden (newbie!!!!!!!) | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

This test case is hidden (newbie!!!!!!!)

im learning c#. Arrays how to open hidden test ? i just want to know that what is requested in this test ......................................... heres questions; A game machine has 5 games installed on it: string[] games = { "Alien Shooter", "Tic Tac Toe", "Snake", "Puzzle", "Football" }; C# Write a program to take N number as input and output the corresponding game with N index from the array. If user enters an invalid number that is out of array range, the program should output "Invalid number". and heres my code ; static void Main(string[] args) { string[] games = { "Alien Shooter", "Tic Tac Toe", "Snake", "Puzzle", "Football" }; int n = Convert.ToInt32(Console.ReadLine()); if (n<0 || n>5) { Console.WriteLine("Invalid number"); } else { Console.WriteLine(games[n]); } } and heres result ; Test Case 1 solved Input 0 Your Output; Alien Shooter Expected Output ; Alien Shooter Test Case 2 solved Input 4 Your Output ;nnFootball Expected Output ;nnFootball Test Case 3 solved Input ; 7 Your Output ; Invalid number Expected Output ; Invalid number and there are two more hidden case didnt solved what should i do ??? class ; c# intermediate - Arrays and Strings - Arrays

9th Mar 2023, 4:08 PM
Jun
Jun - avatar
2 Answers
+ 4
The condition for the "Invalid number" branch needs correction. <games> array only has 5 elements with valid indices ranging from 0 ~ 4. if( n < 0 || n > 4 ) // rest of the code ...
9th Mar 2023, 4:55 PM
Ipang
+ 1
The user still can give a float number as an input (for example "3.4"). So your code would still pass it to the else section, since 3.4 is larger than 0 and smaller than 5. You need to get only integers as input from the user - I think that is the flaw.
9th Mar 2023, 4:30 PM
Paleon
Paleon - avatar