Sure, here's a simple C# quiz with multiple-choice questions. Each question is followed by four options, labeled A, B, C, and D
Example
using System;
class Program
{
static void Main(string[] args)
{
// Quiz questions
string[] questions = {
"What is the capital of France?",
"Who is the author of 'To Kill a Mockingbird'?",
"What is the result of 2 + 2 * 2?",
"Which of the following is not a primitive data type in C#?"
};
// Options for each question
string[,] options = {
{"A. London", "B. Paris", "C. Rome", "D. Madrid"},
{"A. Mark Twain", "B. Harper Lee", "C. J.K. Rowling", "D. George Orwell"},
{"A. 6", "B. 4", "C. 8", "D. 2"},
{"A. int", "B. string", "C. float", "D. boolean"}
};
// Correct answers
string[] answers = {"B", "B", "A", "B"};
// Initialize variables for score and user's answer
int score = 0;
string userAnswer;
// Loop through each question
for (int i = 0; i < questions.Length; i++)
{
// Display the question
Console.WriteLine(questions[i]);
// Display the options
for (int j = 0; j < 4; j++)
{
Console.WriteLine(options[i, j]);
}
// Prompt the user for an answer
Console.Write("Enter your answer (A, B, C, or D): ");
userAnswer = Console.ReadLine().ToUpper();
// Check if the answer is correct
if (userAnswer == answers[i])
{
Console.WriteLine("Correct!");
score++;
}
else
{
Console.WriteLine("Incorrect!");
}
Console.WriteLine();
}
// Display the final score
Console.WriteLine("Your final score is: " + score + "/" + questions.Length);
}
}
This quiz covers a range of topics such as general knowledge, literature, arithmetic, and programming concepts. You can customize the questions, options, and correct answers according to your preferences. Just modify the questions
, options
, and answers
arrays accordingly