Correzione funzioni di ricerca

This commit is contained in:
La Programmatrice Verde 2025-09-23 22:27:55 +02:00
parent a490b54038
commit 393f7b1345

View File

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