What I'm trying to do is let the user search for the number of values falseeither truein boolVector. It is also important that the program handles input errors.
I think I need to use it Convert.Boolean, but I don’t know how to do it. At the moment, I continue to receive the same, regardless of whether I am looking for numbers or letters.
static void Main(string[] args)
{
Random newRandom = new Random();
int slumpTal = newRandom.Next(1, 101);
bool[] boolVektor = new bool[slumpTal];
for (int i = 0; i < boolVektor.Length; i++)
{
int slump = newRandom.Next(0, 2);
if (slump == 0)
boolVektor[i] = true;
else
boolVektor[i] = false;
}
{
Console.Write("Skriv in sökOrd: ");
string searchWord = Console.ReadLine();
bool search = false;
for (int i = 0; i < boolVektor.Length; i++)
{
if (boolVektor[i] == search)
{
Console.WriteLine("The following were found: " + boolVektor[i]);
search = true;
}
if (!search)
{
Console.WriteLine("Your search failed");
}
}
Console.ReadLine();
}
}
source
share