andretafta

Soal Array

Aug 30th, 2024
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.91 KB | None | 0 0
  1. using System;
  2.  
  3. namespace ArrayGame
  4. {
  5.     class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             string[] games = { "Alien Shooter", "Tic Tac Toe", "Snake", "Puzzle", "Football" };
  10.             string input = Console.ReadLine();
  11.  
  12.             // Convert input to integer
  13.             if (int.TryParse(input, out int index))
  14.             {
  15.                 // Check if index is within valid range
  16.                 if (index >= 1 && index <= games.Length)
  17.                 {
  18.                     // Display the game at the specified index
  19.                     Console.WriteLine(games[index]);
  20.                 }
  21.                 else
  22.                 {
  23.                     Console.WriteLine("Nomor game tidak valid.");
  24.                 }
  25.             }
  26.             else
  27.             {
  28.                 Console.WriteLine("Input tidak valid. Harap masukkan angka.");
  29.             }
  30.         }
  31.     }
  32. }
Add Comment
Please, Sign In to add comment