private static void PrintResultStatistics(TestResult testResult) { Console.WriteLine("Всего вопросов: " + testResult.QuestionsCount); Console.WriteLine("Правильных ответов: {0} ({1:0.##}%)", testResult.RightAnswers, (testResult.RightAnswers * 100) / testResult.QuestionsCount); Console.WriteLine("Неправильных ответов: {0} ({1:0.##}%)", testResult.WrongAnswers, (testResult.WrongAnswers * 100) / testResult.QuestionsCount); }
private static TestResult RunTest(List<Question> questions) { var result = new TestResult {QuestionsCount = questions.Count}; foreach (var question in questions) { Console.WriteLine(question.Text); for (int i = 0; i < question.Answers.Count; i++) { Console.WriteLine((i + 1).ToString(CultureInfo.InvariantCulture) + ") " + question.Answers[i]); } var stringAnswer = Console.ReadLine() ?? ""; var answerIndex = int.Parse(stringAnswer) - 1; if (answerIndex == question.CorrectAnswerIndex) { result.RightAnswers++; Console.WriteLine("Вы восхитительны!"); } else { result.WrongAnswers++; Console.WriteLine("А правильный ответ на самом деле: " + question.Answers[question.CorrectAnswerIndex]); } Console.WriteLine(); } return result; }