This repository was archived by the owner on Jun 17, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
54 lines (44 loc) · 1.39 KB
/
Program.cs
File metadata and controls
54 lines (44 loc) · 1.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
using System;
using System.Collections.Generic;
using System.IO;
class Program
{
static void Main()
{
// Prompt a number from 3 to 10
int number = PromptNumber();
// Load dictionary words of the same length as the number
List<string> words = LoadDictionaryWords(number);
// Select a random word
Random random = new Random();
string randomWord = words[random.Next(words.Count)];
Console.WriteLine($"Random word of length {number} is: {randomWord}");
}
static int PromptNumber()
{
int number;
do
{
Console.Write("Enter a number from 3 to 10: ");
} while (!int.TryParse(Console.ReadLine(), out number) || number < 3 || number > 10);
return number;
}
static List<string> LoadDictionaryWords(int length)
{
string dictionaryFilePath = "dictionary.txt";
//Za g-n Kunis, moje da go smenite s neshto drugo
List<string> words = new List<string>();
using (StreamReader reader = new StreamReader(dictionaryFilePath))
{
string word;
while ((word = reader.ReadLine()) != null)
{
if (word.Length == length)
{
words.Add(word);
}
}
}
return words;
}
}