Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Program
- {
- static Action<dynamic> print = Console.Write;
- public class Question
- {
- int correctAnswer;
- double points;
- string text;
- string[] options;
- public Question(int correctAnswer, double points, string text, string[] options)
- {
- this.correctAnswer = correctAnswer;
- this.points = points;
- this.text = text;
- this.options = options;
- }
- public double GetAnswer()
- {
- print(text + "\n\n");
- for (int i = 0; i < options.Length; i++)
- {
- print($"{i + 1}: {options[i]}\n");
- }
- print("Select your answer:\n\n");
- int answer = int.Parse(Console.ReadLine());
- if (answer == correctAnswer)
- {
- print("\nCorrect.\n\n");
- return points;
- }
- else
- {
- print("\nWrong.\n\n");
- return 0;
- }
- }
- }
- static void Main(string[] args)
- {
- List<Question> quiz = new List<Question>();
- //correctAnswer, points, text, {options...}
- quiz.Add(new Question(1, 42.0, "What's the best anime?", new[] { "DBZ", "Naruto", "Bleach"}));
- quiz.Add(new Question(2, 99.0, "Should Death be admin?", new[] { "No.", "Yes."}));
- double total = 0;
- foreach (var question in quiz)
- total += question.GetAnswer();
- print($"Your final score is: {total}\n");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment