From c8e58d8048ce02e48c13a40b7a823447166148f7 Mon Sep 17 00:00:00 2001 From: st529yr Date: Wed, 20 Mar 2024 16:59:06 +0100 Subject: [PATCH] funguje --- cv5/program.c | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/cv5/program.c b/cv5/program.c index 91c28c9..bcf30b7 100644 --- a/cv5/program.c +++ b/cv5/program.c @@ -50,10 +50,22 @@ int main() { return 1; } - // Pridanie študenta do databázy - strcpy(database[size].name, name); - database[size].votes = votes; - size++; + // Hľadanie študenta v databáze + int found = 0; + for (int j = 0; j < size; j++) { + if (strcmp(database[j].name, name) == 0) { + database[j].votes += votes; + found = 1; + break; + } + } + + // Pridanie nového študenta do databázy + if (!found) { + strcpy(database[size].name, name); + database[size].votes = votes; + size++; + } } // Zoradenie databázy podľa počtu hlasov a abecedne