I want to make a program that generates 20 random numbers and search the array for a number. If one of the 20 random numbers was typed in the input the output should say "it is here". If the number is not in the ReadLine it should say"Yes it is there".I want to know how to make all 20 random numbers to be able to search. The code right now can only search the number on the right. Even if the input is one of the 20 random numbers except for the one on the right it would say "No it is not here."
The picture is my current output. IT IS SHOWING 20 NUMBERS.Output1Output2
public static void Main(string[] args)
{
Random random = new Random();
int[] myIntArray = new int[100];
for (int i = 1; i <= 20; i++)
{
int x = random.Next(100);
myIntArray[i] = x;
Console.Write(myIntArray[i] + " ");
if (i == 20)
{
Console.Write("\nType a number to search for:");
int z = Convert.ToInt32(Console.ReadLine());
if (z == x)
{
Console.WriteLine("Yes it is there.");
}
else
{
Console.WriteLine("No it is not here.");
}
}
}
Console.ReadKey();
}
Aucun commentaire:
Enregistrer un commentaire