using System.Collections.Generic;
Console.WriteLine("Podaj kwotę słowną (np. 'dwa miliony trzysta tysięcy pięćdziesiąt sześć złotych i 12 groszy'):");
string input = Console.ReadLine();
float amount = ConvertWordsToFloat(input);
Console.WriteLine($"Wartość kwoty to: {amount} zł.");
Console.WriteLine($"Błąd konwersji: {ex.Message}");
static float ConvertWordsToFloat(string input)
Dictionary<string, int> wordToNumber = new Dictionary<string, int>
{ "zero", 0 }, { "jeden", 1 }, { "dwa", 2 }, { "trzy", 3 },
{ "cztery", 4 }, { "pięć", 5 }, { "sześć", 6 }, { "siedem", 7 },
{ "osiem", 8 }, { "dziewięć", 9 }, { "dziesięć", 10 },
{ "jedenaście", 11 }, { "dwanaście", 12 }, { "trzynaście", 13 },
{ "czternaście", 14 }, { "piętnaście", 15 }, { "szesnaście", 16 },
{ "siedemnaście", 17 }, { "osiemnaście", 18 }, { "dziewiętnaście", 19 },
{ "dwadzieścia", 20 }, { "trzydzieści", 30 }, { "czterdzieści", 40 },
{ "pięćdziesiąt", 50 }, { "sześćdziesiąt", 60 }, { "siedemdziesiąt", 70 },
{ "osiemdziesiąt", 80 }, { "dziewięćdziesiąt", 90 },
{ "sto", 100 }, { "dwieście", 200 }, { "trzysta", 300 },
{ "czterysta", 400 }, { "pięćset", 500 }, { "sześćset", 600 },
{ "siedemset", 700 }, { "osiemset", 800 }, { "dziewięćset", 900 },
{ "tysiąc", 1000 }, { "milion", 1000000 }, { "miliony", 1000000 }
input = input.ToLower().Replace("złoty", "").Replace("złote", "").Replace("groszy", "").Replace("grosze", "").Replace("i", "").Trim();
string[] parts = input.Split(new[] { "groszy", "grosze" }, StringSplitOptions.RemoveEmptyEntries);
throw new Exception("Niepoprawny format kwoty.");
string mainPart = parts[0].Trim();
string groszyPart = parts.Length > 1 ? parts[1].Trim() : "";
int result = ConvertWordsToNumber(mainPart, wordToNumber);
if (!string.IsNullOrEmpty(groszyPart))
groszy = ConvertWordsToNumber(groszyPart, wordToNumber);
return result + groszy / 100f;
static int ConvertWordsToNumber(string input, Dictionary<string, int> wordToNumber)
string[] words = input.Split(new[] { ' ', '-' }, StringSplitOptions.RemoveEmptyEntries);
foreach (var word in words)
if (wordToNumber.ContainsKey(word))
int number = wordToNumber[word];
if (number == 1000000 || number == 1000)
throw new Exception($"Nie rozpoznano słowa: {word}");