diff --git a/Program.cs b/Program.cs index 1ce710f..0a0832d 100644 --- a/Program.cs +++ b/Program.cs @@ -11,9 +11,7 @@ class Program { bool rubricaNonVuota = false; bool error; int contatore = 0; - string nomeesatto; - string nomeapprossimato; - string messaggio; + string ricerca; string[] nomi = new string[DIMENSIONE_RUBRICA]; string[] numeriditelefono = new string[DIMENSIONE_RUBRICA]; Voce singolavoce = null; @@ -77,21 +75,23 @@ class Program { } else { do { - check2 = false; + string? message; + error = true; Console.WriteLine("Inserisci il nome esatto che stai cercando"); - nomeesatto = Console.ReadLine(); - nomeesatto = nomeesatto.ToLower(); - check2 = VerificaCorrettezza(nome, true); - if (nomeesatto.Length > 40) { - Console.WriteLine("il nome non può essere lungo più di 40 caratteri"); + ricerca = Console.ReadLine().ToLower(); + + message = Controllo(ricerca, true, 0, rubrica); //lo zero serve per saltare il controllo per verificare se il nome esiste già o meno + + if (message != null) { + Console.WriteLine(message); } - if (check2 == true) { - Console.WriteLine("il nome non può contenere dei numeri"); + else { + error = false; } } - while (nomeesatto.Length > 40 || check2 == true); - messaggio = rubrica.Ricerca(nomeesatto, true, contatore); - Console.WriteLine(messaggio); + while (error); + + Console.WriteLine(rubrica.Ricerca(ricerca, true, contatore)); } break; case 3: @@ -100,20 +100,23 @@ class Program { } else { do { - check2 = false; - Console.WriteLine("Inserisci il nome approsimato che stai cercando"); - nomeapprossimato = Console.ReadLine(); - nomeapprossimato = nomeapprossimato.ToLower(); - check2 = VerificaCorrettezza(nome, true); - if (nomeapprossimato.Length > 40) { - Console.WriteLine("il nome non può essere lungo più di 40 caratteri"); + string? message; + error = true; + Console.WriteLine("Inserisci il nome approssimato che stai cercando"); + ricerca = Console.ReadLine().ToLower(); + + message = Controllo(ricerca, true, 0, rubrica); //lo zero serve per saltare il controllo per verificare se il nome esiste già o meno + + if (message != null) { + Console.WriteLine(message); } - if (check2 == true) { - Console.WriteLine("il nome non può contenere dei numeri"); + else { + error = false; } } - while (nomeapprossimato.Length > 40 || check2 == true); - rubrica.Ricerca(nomeapprossimato, false, contatore); + while (error); + + Console.WriteLine(rubrica.Ricerca(ricerca, false, contatore)); } break; case 4: