0

I'M trying to learn to program through Mono. I'M using a book on C#. Although it isn't specifically for Mono, I haven't gotten far into the book and it's a really small example so I don't expect that it has any platform specific code. Please see what's wrong with this code.

namespace Song
{
	class ThisOldMan
	{
		static void Main(string[] args)
		{
			doVerse(1);
			doChorus();
			doVerse(2);
			doChorus();
		}
		
		static void doChorus()
		{
			string message = "";
			message += "\n...With a knick-knack paddy whack\n";
			message += "Give a dog a bone\n";
			message += "This old man came rolling home.";
			message += "\n\n";
		} // end doChorus
		
		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);
		} // end verse
		
		static string getPlace(int verseNum)
		{
			string message = "";
				switch(verseNum)
			{
			 case1:
				message = "on mu thumb ";
				break;
			 case2:
				message = "on my shoe ";
				break;
			default:
				message = "not yet defined";
				break;
			} // end switch
			return message;
		} // end getPlace
		
		static void pause()
		{
			Console.ReadLine();
		}
	}
}
3
Contributors
4
Replies
5
Views
7 Years
Discussion Span
Last Post by ddanbe
1

The problem is in your cases inside the switch. Specifically, you're missing a space between "case" and the value your testing for.

0

Line 26 message += verseNum; should read message += verseNum.ToString();
You cannot assign integers to strings, so first convert your integer verseNum to a string with the ToString method.

1

Line 26 message += verseNum; should read message += verseNum.ToString();
You cannot assign integers to strings, so first convert your integer verseNum to a string with the ToString method.

I thought so at first, too, but that actually works. It's not best practice, that's for sure.

0

Thanks for pointing that out apegram! Learned something here.
Apparently you can concatenate an integer,double, boolean etc. to a string, but you are still not allowed to assign those types to a string.
Thought it was Mono, but the same under VS.

Edited by ddanbe: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.