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

Popular posts from this blog

javascript - Chart.js (Radar Chart) different scaleLineColor for each scaleLine -

apache - Error with PHP mail(): Multiple or malformed newlines found in additional_header -

java - Android – MapFragment overlay button shadow, just like MyLocation button -