Exquisite Corpse

I am having various problems with course as when I put the code in they say that the keyword can’t be followed and I cannot convert void into int.
This is where the code’s error occurs:

static void TranslateToNumber(string creature)
{
switch (creature)
{
case “ghost”:
return 1;

    case "bug":
      return 2;
      
    case "monster":
      return 3;
      
    default:
      return 1;
  }
  int headNum = "body";
  int bodyNum = "feet";
  int feetNum = "head";
}

And this is the entire code:

using System;

namespace ExquisiteCorpse
{
class Program
{
static void Main(string args)
{
RandomMode();
}

static void BuildACreature(string head, string body, string feet)
{
  
}

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 SwitchCase(int head, int body, int feet)
{
  
}

static void TranslateToNumber(string creature)
{
  switch (creature)
  {
    case "ghost":
      return 1;
      
    case "bug":
      return 2;
      
    case "monster":
      return 3;
      
    default:
      return 1;
  }
  int headNum = "body";
  int bodyNum = "feet";
  int feetNum = "head";
}

public static void GhostHead()
{
  Console.WriteLine("     ..-..");
  Console.WriteLine("    ( o o )");
  Console.WriteLine("    |  O  |");
}

public static void GhostBody()
{
  Console.WriteLine("    |     |");
  Console.WriteLine("    |     |");
  Console.WriteLine("    |     |");
}

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

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

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

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

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

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

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

}
}

Not exactly sure what you are trying to do with this function, but it has a few issues. You cannot have a return statement in a function declared with void. void means that there will be no return type. Your switch block returns int's, so you probably want static int TranslateToNumber(string creature).
Next problem is the last 3 lines of the function. You cannot declare an int variable, and assign a string to it. It’s important to note, however, that those 3 lines will never be executed. Your switch block contains the keyword return in every case, so control will be passed back to the line of code that called the function immediately with the return value once a return is reached.

What exactly should the code be then

I haven’t done this project myself, but to clear your error, you just need to change void to int, and delete the 3 lines assigning strings to int variables. If those variables are required for the project, they belong somewhere else. I briefly looked at the instructions, and the only thing this function is supposed to do is return an int that is determined by the string creature you pass to the function.

Do you know anyone that has?

No. I don’t. If you continue to post your code as you have questions or errors, I’ll help you, but even if I had done this project, I wouldn’t just give you the solution. Finding and fixing errors is a great learning experience. I haven’t completed the C# course here on Codecademy, but I learned C# years ago through another resource, and have a fair amount of experience in the language. If you have specific questions, feel free to ask, but most of us on the forum won’t just provide entire solutions. Good luck, and keep at it!

Okay. Now I have completed the project, and as I stated before, you can’t return anything from a method declared with void. That is what is giving you the error regarding converting void to int. The declaration of the TranslateToNumber() method should include the data type that the method will return. You are returning either 1, 2 or 3, so it should be declared as follows:

static int TranslateToNumber(string creature)

Your switch block is perfectly fine, but the 3 lines below it do not belong in the TranslateToNumber() method. They will be declared in the BuildACreature() method and assigned values using the TranslateToNumber() method. (See steps 17 & 18).

Good luck && Happy coding! Feel free to post your code, and ask additional questions if you need more help.

1 Like

Okay I got that done but in the last couple of steps I don’t get why it isn’t printing out a creature when I put in the command.
This is my current code:
using System;

namespace ExquisiteCorpse
{
class Program
{
static void Main(string args)
{
RandomMode();
}

static void BuildACreature(string head, string body, string feet)
{
  int headNum = TranslateToNumber("body");
  int bodyNum = TranslateToNumber("feet");
  int feetNum = TranslateToNumber("head");
}

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);
}

static void SwitchCase(int head, int body, int feet, int headNum, int bodyNum, int feetNum)
{
  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 int TranslateToNumber(string creature)
{
  switch (creature)
  {
    case "ghost":
      return 1;
      
    case "bug":
      return 2;
      
    case "monster":
      return 3;
      
    default:
      return 1;
  }
}

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("   \"\"\"\" \"\"\"\"");
}

}
}

Okay. Your SwitchCase() method should only accept 3 parameters not 6. Should only accept (int head, int body, int feet).
If you read instruction #13 carefully, you’ll see that you are supposed to call the SwitchCase() method at the end of the RandomMode() method.

13.
Now, return to the RandomMode() method. Call the SwitchCase() method after the int variable definitions.

Make sure to pass in the variables head , body , and feet as arguments to the SwitchCase() method. That way, each time we run the program, a new set of numbers will be passed to that method and the output will change.

Those changes will make your program work. I was a little disappointed that the project doesn’t include instructions for actually using the BuildACreature() method. You can use it, by calling SwitchCase() as the last line inside the method, and passing (headNum, bodyNum, feetNum) as arguments. Then you also need to add a call to BuildACreature() inside the Main() method. When you do, you have to select which parts you want like so:

BuildACreature("bug", "monster", "ghost");

That would give you a bug head, monster body and ghost feet.

Good luck! You’re almost there!

1 Like

Hi
I do not understand what they want from me in 19.
19.
Pass the new int variables into the SwitchCase() method as arguments. Congratulations, you just refactored your code using methods!

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

            switch (body)
            {
                case 1:
                    BugBody();
                    break;
                case 2:
                    GhostBody();
                    break;
                case 3:
                    MonsterBody();
                    break;
                default:
                    break;
            }

            switch (feet)
            {
                case 1:
                    BugFeet();
                    Console.WriteLine("\n");
                    break;
                case 2:
                    GhostFeet();
                    Console.WriteLine("\n");
                    break;
                case 3:
                    MonsterFeet();
                    Console.WriteLine("\n");
                    break;
                default:
                    break;
            }

        }

I thought I understood the whole project until this line 19 threw me off.

I now have an app that has a method BuildACreature, SwitchCase, TranslateToNumber and RandomMode.

But I am not exactly sure what I built in a sense. If I call RandomMode and run it, it works really nicely.

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);
        }

If I call TranslateToNumber(“bug”); - or anything, it does nothing.

static int TranslateToNumber(string creature)
        {
            switch (creature)
            {
                case "bug":
                    return 1;
                case "ghost":
                    return 2;
                case "monster":
                    return 3;
                default:
                    return 1;
            }
        }

If I call SwitchCase it works nicely.

So what exactly was the purpose of the last few steps? You are able to call string to int and the other way around - I think?

What about it? How does it help me?

Does this mean I can tell my user to write 1, 2, 3 or bug, monster, ghost and either way is intended to print out a result?

Thanks in advance…

Hello, @real_arbitrary.

From what I can see, and what you’ve described, it looks like you’ve done a great job building what was expected. From what I recall, having done this project some time ago, step 19 is a step allowing for random generation of a ‘corpse’ using the RandomMode() method. You can randomly generate numbers, and then the SwitchCase method converts the numbers to the corresponding parts.

I suppose that’s up to you. You just have to make sure that you supply the correct arguments to the correct methods. I just went to the project to see, and it appears that in this environment, you could actually write code to get user input (not all of the lessons/projects have a console pane that will allow user input), and then use that input to determine whether to call RandomMode(), or to generate a specific ‘corpse’ like ‘bug’, or you could even allow the user to choose which creature’s parts are assigned to each section (head, body, feet). These features would be beyond the scope of the project, but could be fun to implement.

I’m not sure I answered your questions. The project shows how to use some of the things you’ve learned so far, and isn’t necessarily a good ‘real world’ example of a useful program. You, as the programmer, however, are free to build on this project, and make it as useful or interactive as you like. Taking the lessons and projects a step or two beyond what is expected (after passing the required steps) is a great way to learn.

1 Like

Thanks for your reply.

Your input was valuable. I went back to this now and watched the video where the pro programmer was working.

I found that my app is the same as what he did, yet when I run my BuildACreature(“monster”, “bug”, “ghost”); my TransLateToNumber(): always returns the default of 1.

I took the liberty of putting the app I am working on on Github (if you execute number 4 it launches the code for Exquisite Corpse) - My app on GitHub here

Can anyone please help me out?

What input do you give your TranslateToNumber method? What does TranslateToNumber do with that input? Based on the code in that method, what would you need to enter to for example get 2?

So I call BuildACreature here:


Inside BuildACreature:
image
And then TransLateToNumber:
image
Overview:

What input do you give your TranslateToNumber method? What does TranslateToNumber do with that input? Based on the code in that method, what would you need to enter to for example get 2?

-> I give TransLateToNumber a string
-> TransLateToNumber returns an int
-> If you wanted 2 you would provide “ghost”

I keep hitting the default return thuogh.

right but, what string did you use? you’d need to use “ghost” or “monster”, otherwise what would you get?

I gave it BuildACreature(“ghost”, “monster”, “bug”);
You know? Statically to just get it working.
My idea is to let a user decide so I can make it dynamic.

That’s a different method.

You have some method that is returning something other than what you expected.
So, what input did you give it, and what output did you get, and was the input wrong, or was the response wrong?

When something’s wrong, you’d observe what happened and compare what you see to what you meant should happen, and when you have found the difference you know what to change.

When in doubt, print it out. Is the input truly what you intended? If the output is unexpected, something must not be going according to plan. To find where things change from what you expected, you can print the values before and after each step to see what is happening. For example you might try:

static int TranslateToNumber(string creature)
{
    Console.WriteLine(creature); //Does this print what you expected? If so, great, check the next thing. If not, why not? Go back to where the value came from, and continue making observations.
    switch (creature)
    {

Here is my code for the assignment without the additional assigments
(there is also a proposed solution on Youtube: Get Help --> Project Wolkthrough)

using System;

namespace ExquisiteCorpse
{
  class Program
  {
    static void Main(string[] args)
    {
      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 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 SwitchCase(int head, int body, int feet)
    {
      switch (head)
      {
        case 1:
          GhostHead();
          break;
          
        case 2:
          BugHead();
          break;
          
        case 3:
          MonsterHead();
          break;
          
        default:
          Console.WriteLine("Error. No valid number.");
          break;
            
      }
      
      switch (body)
      {
        case 1:
          GhostBody();
          break;
          
        case 2:
          BugBody();
          break;
          
        case 3:
          MonsterBody();
          break;
          
        default:
          Console.WriteLine("Error. No valid number.");
          break;
          
      }
      
      switch (feet)
      {
        case 1:
          GhostFeet();
          break;
          
        case 2:
          BugFeet();
          break;
          
        case 3:
          MonsterFeet();
          break;
          
        default:
          Console.WriteLine("Error. No valid number.");
          break;
          
      }
    }
    
    static int TranslateToNumber (string creature)
    {
      switch (creature)
      {
        case "ghost":
          return 1;
          
        case "bug":
          return 2;
          
        case "monster":
          return 3;
          
        default:
          return 1;
      }
    }

    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("   \"\"\"\" \"\"\"\"");
    }
  }
}

I still have no idea though how you can code the first additional assignment:

Extend the BuildACreature() method so that all of its parameters are optional. It should assign a random body part if a parameter is not specified.

I keep getting this error message while doing this project but my code seems to be the same as everyone else’s. Any ideas?