Requesting advice on what I've done wrong here

Hello,

I continually get stuck at the end of the exquisite corpse project. I was able to get to around step 18 without referring to the video, but got a bit stumped after that. I watched the video for the answers and my code should be complete now, but trying to run it only gives me an error about loose static functions not being available in C# 7.3. Please help me, it’s appreciated.

using System;

namespace ExquisiteCorpse
{
  class Program
  {
    static void Main(string[] args)
    {
      BuildACreature();
      RandomMode();
    }
    
    static void BuildACreature(string head, string body, string feet)
    {
      int headNum = TranslateToNumber(head);
      int bodyNum = TranslateToNumber(body);
      int feetNum = TranslateToNumber(feet);

      SwitchCase(headNum, bodyNum, feetNum);

    }
    static void SwitchCase(int head, int body, int feet)
    {
      switch(head)
      {
        case 1:
        GhostHead();
        break;

        case 2:
        BugHead();
        break;

        case 3:
        MonsterHead();
        break;
      }
      switch(body)
      {
        case 1:
        GhostBody();
        break;

        case 2:
        BugBody();
        break;

        case 3:
        MonsterBody();
        break;
      }
      switch(feet)
      {
        case 1:
        GhostFeet();
        break;

        case 2:
        BugFeet();
        break;

        case 3:
        MonsterFeet();
        break;
      }
      static void TranslateToNumber(string creature)
      {
        switch(creature)
        {
          case "ghost":
          return 1;
          break;

          case "bug":
          return 2;
          break;

          case "monster":
          return 3;
          break;

          default:
          return 1;
          break;
        }
      }
    }
    static void RandomMode()
    {
     Random randomNumber = new Random();
     int head = randomNumber.Next(1, 4);
     int body = randomNumber.Next(1, 4);
     int feet = randomNumber.Next(1, 4);
     SwitchCase(head, body, feet); 
    }
    static void GhostHead()
    {
      Console.WriteLine("     ..-..");
      Console.WriteLine("    ( o o )");
      Console.WriteLine("    |  O  |");
    }
    static void GhostBody()
    {
      Console.WriteLine("    |     |");
      Console.WriteLine("    |     |");
      Console.WriteLine("    |     |");
    }

    static void GhostFeet()
    {
      Console.WriteLine("    |     |");
      Console.WriteLine("    |     |");
      Console.WriteLine("    '~~~~~'");
    }

    static void BugHead()
    {
      Console.WriteLine("     /   \\");
      Console.WriteLine("     \\. ./");
      Console.WriteLine("    (o + o)");
    }

    static void BugBody()
    {
      Console.WriteLine("  --|  |  |--");
      Console.WriteLine("  --|  |  |--");
      Console.WriteLine("  --|  |  |--");
    }

    static void BugFeet()
    {
      Console.WriteLine("     v   v");
      Console.WriteLine("     *****");
    }

    static void MonsterHead()
    {
      Console.WriteLine("     _____");
      Console.WriteLine(" .-,;='';_),-.");
      Console.WriteLine("  \\_\\(),()/_/");
      Console.WriteLine("   (,___,)");
    }

    static void MonsterBody()
    {
      Console.WriteLine("   ,-/`~`\\-,___");
      Console.WriteLine("  / /).:.('--._)");
      Console.WriteLine(" {_[ (_,_)");
    }

    static void MonsterFeet()
    {
      Console.WriteLine("    |  Y  |");
      Console.WriteLine("   /   |   \\");
      Console.WriteLine("   \"\"\"\" \"\"\"\"");
    }
  }
}

Take a look at the curly braces for SwitchCase(). It appears that the TranslateToNumber() method is enclosed within SwitchCase().

A technique I use to track the opening and closing braces is to use a comment at the end of each method:

       ...   
    } // end RandomMode()

    static void SwitchCase(int head, int body, int feet)
    {
      switch (head)
      {
        case 1:
          GhostHead();
          break;
        case 2:
          BugHead();
          break;
        case 3:
          MonsterHead();
          break;
        default:
          break;
      }
      switch (body)
      {
       ...
      }
      switch (feet)
      {
        ...
      }
    } // end SwitchCase()
1 Like

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.