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 😀
Change your
getPlacemethod to this:I’m guessing this is homework,so I’ll explain why it wasn’t working. You had two errors:static voidand you were trying to return a
string. You had to replacevoidwith
stringto indicate that themethod returns a
string.variable called
verseNumwhich wasnot present in the method. To pass
in the variable you have to include
it within the method signature.