c# - Prompting User Input and Displaying User Output Using An Array -
i need help. need prompt user enter index between 0 , 9. if user enters outside of array, need use "if" statement or "try catch" tell user "no such score exists". have far.
public class program { public static void main(string[] args) { int[] gamescores = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; console.writeline("please enter index between 0 , 9"); int gamescores = int.parse(console.readline()); (int = 0; < gamescores.length;i++) { gamescores[i] = int.parse(console.readline()); } } // end main
instead of using loop directly use contains check wheather desired value present in array or not. try out.
int[] gamescores = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; console.writeline("please enter index between 0 , 9"); int gamescores = int.parse(console.readline()); if (gamescores.contains(gamescores)) { console.writeline("score exists"); } else { console.writeline("no such score exists"); }
Comments
Post a Comment