Untitled
unknown
csharp
2 months ago
1.5 kB
7
Indexable
Console.WriteLine("Witamy w quizie wiedzy!"); Console.WriteLine("Odpowiedz na pytania wpisując numer odpowiedzi."); Console.WriteLine("Za każdą poprawną odpowiedź otrzymasz 1 punkt."); string[] questions = { "Ile nóg ma pająk?", // 0 "Która planeta jest najbliżej Słońca?", // 1 "Jaki jest wynik działania 5 + 3?", // 2 "Stolica Polski to?", // 3 "Jaki jest największy ocean na Ziemi?" // 4 }; string[,] answers = { { "1. Sześć", "2. Osiem", "3. Dziesięć" }, { "1. Wenus", "2. Mars", "3. Merkury" }, { "1. Siedem", "2. Osiem", "3. Dziewięć" }, { "1. Warszawa", "2. Kraków", "3. Gdańsk" }, { "1. Atlantycki", "2. Spokojny", "3. Indyjski" } }; int[] correctAnswers = { 2, 3, 2, 1, 2 }; int score = 0; for (int i = 0; i < questions.Length; i++) { Console.WriteLine($"\nPytanie {i + 1}: {questions[i]}"); for (int j = 0; j < 3; j++) { Console.WriteLine(answers[i, j]); } Console.WriteLine("Twoja odpowiedz (wpisz numer): "); int userAnswer = 0; while (!int.TryParse(Console.ReadLine(), out userAnswer) || userAnswer < 1 || userAnswer > 3) { Console.WriteLine("Podaj poprawny numer odpowiedzi (1,2 lub 3)"); } if (userAnswer == correctAnswers[i]) { Console.WriteLine("Brawo! To jest poprawna odpowiedź!"); score++; } else { Console.WriteLine("Niestety to jest błędna opowiedź!"); } } Console.WriteLine($"\nKoniec gry! Twój wynik to: {score} punktów na {questions.Length} możliwych.");
Editor is loading...
Leave a Comment