From 84bec1c7d2d1127e235d4e3fec991bd38439e522 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tam=C3=A1=C5=A1?= Date: Thu, 29 Feb 2024 10:20:41 +0000 Subject: [PATCH] Update 'cv2/program.c' --- cv2/program.c | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/cv2/program.c b/cv2/program.c index 3572777..b8af2fc 100644 --- a/cv2/program.c +++ b/cv2/program.c @@ -4,7 +4,6 @@ int main() { int results[50]; int count = 0, num; int maxPoharov = 0; - int maxIndex = -1; while (count < 50 && scanf("%d", &num) == 1) { if (num <= 0) { @@ -13,22 +12,24 @@ int main() { results[count] = num; if (num > maxPoharov) { maxPoharov = num; - maxIndex = count; } count++; } + + if (count == 0) { + printf("Chyba: Málo platných hodnôt.\n"); + return 0; // Ukončí program + } + for (int i = 0; i < count; i++) { printf("Súťažiaci č. %d vypil %d pohárov.\n", i + 1, results[i]); } - - if (maxIndex != -1) { - - for (int i = 0; i < count; i++) { - if (results[i] == maxPoharov) { - printf("Výherca je súťažiaci %d ktorý vypil %d pohárov.\n", i + 1, maxPoharov); - } + + for (int i = 0; i < count; i++) { + if (results[i] == maxPoharov) { + printf("Výherca je súťažiaci %d ktorý vypil %d pohárov.\n", i + 1, maxPoharov); } }