Building A Mad Libs Game

Lesson 10
Author : Afrixi
Last Updated : February, 2023
C# - Programming Language
This course covers the basics of programming in C#.

here’s an example of a simple Mad Libs game that prompts the user to enter words and then outputs a story using those words:

using System;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Welcome to the Mad Libs Game!");

            Console.WriteLine("Please enter an adjective:");
            string adj1 = Console.ReadLine();

            Console.WriteLine("Please enter a noun:");
            string noun1 = Console.ReadLine();

            Console.WriteLine("Please enter a verb:");
            string verb1 = Console.ReadLine();

            Console.WriteLine("Please enter an adverb:");
            string adv1 = Console.ReadLine();

            Console.WriteLine("Please enter another adjective:");
            string adj2 = Console.ReadLine();

            Console.WriteLine("Please enter another noun:");
            string noun2 = Console.ReadLine();

            Console.WriteLine("Please enter another verb:");
            string verb2 = Console.ReadLine();

            Console.WriteLine("Please enter another adverb:");
            string adv2 = Console.ReadLine();

            Console.WriteLine("Please enter a past-tense verb:");
            string pastVerb = Console.ReadLine();

            Console.WriteLine("Once upon a time, there was a " + adj1 + " " + noun1 + " who loved to " + verb1 + " " + adv1 + ".");
            Console.WriteLine("One day, the " + noun1 + " met a " + adj2 + " " + noun2 + " who wanted to " + verb2 + " " + adv2 + ".");
            Console.WriteLine("The " + noun1 + " and the " + noun2 + " " + pastVerb + " happily ever after.");

            Console.ReadKey();
        }
    }
}

In this example, we’re using Console.ReadLine() to prompt the user to enter adjectives, nouns, verbs, and adverbs, and then we’re using those words to output a short story. Note that we’re concatenating the words together using the + operator, and we’re using " " to add spaces between the words.

You can modify this example to include more prompts and to output a longer story with more detail.