Lesson 38 +25 XP

Project 3: Mini Quiz App

Project 3: Mini Quiz App

A small multiple-choice quiz that tracks the score.

The goal

Ask three questions, compare answers, and print a final score out of 3.

What you practice

  • Arrays and foreach
  • A List<int> or counter for the score
  • Comparison with ==
  • Loops over questions

Starter code

using System;

string[] questions =
{
  "What is 2 + 2? (a) 3 (b) 4 (c) 5",
  "Which language runs on .NET? (a) Python (b) C# (c) Ruby",
  "What does WriteLine do? (a) print a line (b) read input (c) loop"
};

string[] answers = { "b", "b", "a" };
int score = 0;

for (int i = 0; i < questions.Length; i++)
{
  Console.WriteLine(questions[i]);
  string guess = Console.ReadLine();
  if (guess == answers[i]) score++;
}

Console.WriteLine(
quot;You scored {score} out of {questions.Length}");

Step-by-step

  1. Run the starter and answer correctly to reach 3/3.
  2. Make the comparison case-insensitive (try ToLower()).
  3. Print a "Great!" message when score == 3.
  4. Add a fourth question of your own.

Checklist

  • [ ] Questions and answers are stored in arrays
  • [ ] A loop walks through every question
  • [ ] Correct answers increment the score
  • [ ] The final score is printed
  • [ ] The program runs without errors

TL;DR

  • Arrays hold the questions and answers.
  • A for loop visits each index.
  • Score is just a counter.