views:

69

answers:

1

Hi guys, this is my first time posting my problem here, i hope i get help :)

My Problem:

I am trying to display the "This Old Man" (first two stanzas only) in the Console. I am beginning to learn methods, so please bear my n00bishness.

The Song goes:

This old man, he played one
He played knick−knack on my thumb
With a knick−knack paddy−whack
Give a dog a bone
This old man came rolling home


This old man, he played two
He played knick−knack on my shoe
With a knick−knack paddy−whack
Give a dog a bone
This old man came rolling home

I coded the following:

namespace Song
{
    class Song
    {
        static void Main(string[] args)
        {
            doVerse(1);
            doChorus();
        }
        static void doChorus()
        {
            Console.WriteLine("With a knick−knack paddy−whack");
            Console.WriteLine("Give the dog a bone");
            Console.WriteLine("This old man came rolling home");
            Console.WriteLine();
            Console.ReadLine();
        }
        static void doVerse(int verseNum)
        {
            string message = "";
            message += "This old man, he played ";
            message += verseNum;
            message += ". \nHe played knick−knack ";
            //message += getPlace(verseNum);
            Console.WriteLine(message);
        }
        static void getPlace()
        {
            string message = "";
            switch (verseNum)
            {
                case 1:
                    message = "on my thumb ";
                    break;
                case 2:
                    message = "on my shoe";
                    break;
                default:
                    message = "not yet defined";
                    break;
            }
            return message;
        }
    }
}

Visual studio is giving me the following errors:

http://i56.tinypic.com/fx850m.jpg

I hope you guys understand my intention with this program.

Thanks

Regards,

Kyle :D

A: 

Change your getPlace method to this:

static string getPlace(int verseNum)
{
    string message = "";
    switch (verseNum)
    {
        case 1:
            message = "on my thumb ";
            break;
        case 2:
            message = "on my shoe";
            break;
        default:
            message = "not yet defined";
            break;
    }
    return message;
}

I'm guessing this is homework, so I'll explain why it wasn't working. You had two errors:

  1. You're method was set to static void and you were trying to return a string. You had to replace void with string to indicate that the method returns a string.
  2. You were using a variable called verseNum which was not present in the method. To pass in the variable you have to include it within the method signature.
GenericTypeTea
Thanks GenericTypeTea! Worked!i am beggining to grab hold of these now :)
kylebriffa7
btw this is NOT homework :\ why everyone is saying that?i am trying to learn from various sites ON MY OWN so as school starts i'll be familiar with these, that's all :\
kylebriffa7
Because usually people are lazy and do nothing if not forced by homework's duty. Thus the supposition. Don't worry about it ;)
digEmAll
@kylebriffa7 - A lot of us have obviously been through the whole leaning process at schools and with workbooks, and questions such as this do appear like workbook excercises. Don't take it personally. If it's not homework, no need to worry. People just get arsy about helping with homework as we don't want to do the work for them, we want to HELP them understand what they need to do instead.
GenericTypeTea