<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:wikidot="http://www.wikidot.com/rss-namespace">

	<channel>
		<title>Sample Program in Chapter 8 in Player&#039;s Guide 2nd Edition</title>
		<link>http://rbwhitaker.wikidot.com/forum/t-1977061/sample-program-in-chapter-8-in-player-s-guide-2nd-edition</link>
		<description>Posts in the discussion thread &quot;Sample Program in Chapter 8 in Player&#039;s Guide 2nd Edition&quot; - Couldn&#039;t understand the sample code</description>
				<copyright></copyright>
		<lastBuildDate>Mon, 16 Mar 2026 15:32:16 +0000</lastBuildDate>
		
					<item>
				<guid>http://rbwhitaker.wikidot.com/forum/t-1977061#post-2682015</guid>
				<title>Re: Sample Program in Chapter 8 in Player&#039;s Guide 2nd Edition</title>
				<link>http://rbwhitaker.wikidot.com/forum/t-1977061/sample-program-in-chapter-8-in-player-s-guide-2nd-edition#post-2682015</link>
				<description></description>
				<pubDate>Wed, 02 Nov 2016 02:07:53 +0000</pubDate>
				<wikidot:authorName>rbwhitaker</wikidot:authorName>				<wikidot:authorUserId>88099</wikidot:authorUserId>				<content:encoded>
					<![CDATA[
						 <p>I edited your question to get the syntax highlighting. It just helps me see the code better. Hope that's OK. :D</p> <p>Anyway, on to your questions!</p> <p>You're right, <tt>Console.Write</tt> isn't mentioned or described before this particular problem. In fact, digging a bit further, it doesn't seem to be actually described <em>anywhere</em> in the book. (Though I think most people will pick it up from that sample code there in the book.)</p> <p>Technically speaking, you don't <em>need</em> <tt>Console.Write</tt> to accomplish the task at hand in that particular problem. You could use <tt>Console.WriteLine</tt>. But in this context, <tt>Console.Write</tt> is a bit prettier, and I definitely ought to adjust that chapter to include at least a brief description of it, so that it doesn't catch people off guard. So I appreciate you pointing it out.</p> <p><tt>Convert.ToDouble</tt> isn't intended to convert written-out words into numbers. The scope covered in that method is simply to take a string that stores the numbers themselves (but stored as a string) and turn it into the <tt>double</tt> type.</p> <p>Being able to parse written-out numbers is actually a fairly complex problem. There are lots and lots of things you'd have to account for to make it work well. It probably wouldn't be <em>too</em> hard if you limit the options to just the strings, &quot;zero&quot;, &quot;one&quot;, &quot;two&quot;, &#8230; &quot;nine&quot;. You could do some string comparisons to see if those are a match. But if you open up the options to something far broader (<em>any</em> text representation of numbers, for example) then it becomes a rather complicated natural language processing problem.</p> <p>Consider for example the number 1904.2. If you enter the string &quot;1904.2&quot;, <tt>Convert.ToDouble</tt> will function correctly. But if we want to allow for the user to enter any text representation of that number, there are tons and tons of possibilities. Here are a few examples:</p> <ul> <li>one thousand nine hundred and four point two</li> <li>nineteen oh four point two</li> <li>nineteen hundred and four point two</li> <li>nineteen hundred four point two</li> <li>one nine oh four point two</li> <li>one nine zero four point two</li> <li>one niner zero four point two</li> <li>one thousand nine hundred four and two tenths</li> </ul> <p>Plus a number of typographical variances. Hyphenations, spacing issues, &quot;a&quot; vs. &quot;one&quot;, etc.</p> <p>And that's not even to mention if you want to account for spelling errors. &quot;zreo&quot; instead of &quot;zero&quot; &quot;to&quot; vs. &quot;two&quot; etc.</p> <p>And that's just <em>some</em> of the variants for this one particular number. Other numbers are more complicated, or at least, introduce additional complexities.</p> <p>It's not that that isn't possible. It is. I'm sure there's even a 3rd party library out there that will do all of that for you if you Google it.</p> <p>But hopefully that helps illustrate the complexity of parsing user input when you allow them to enter words when you need numbers (and then try to parse it). If you look around though, nearly every program, application, and website that expects numbers (for a ZIP code, phone number, or whatever) they'll always reject non-numeric input, even if it is technically parsable, or in a written format that a human might be able to understand.</p> <p>But the <tt>Convert.ToWhatever</tt> methods <em>do</em> provide a key role in converting between the built-in types, and I don't think that should get discounted. That's a very useful tool to know about. You'll use it quite often for a variety of things.</p> <p>Anyway, I hope that helps answer some of the things you were wondering about. Don't hesitate to ask if you have other questions!</p> 
				 	]]>
				</content:encoded>							</item>
					<item>
				<guid>http://rbwhitaker.wikidot.com/forum/t-1977061#post-2681600</guid>
				<title>Sample Program in Chapter 8 in Player&#039;s Guide 2nd Edition</title>
				<link>http://rbwhitaker.wikidot.com/forum/t-1977061/sample-program-in-chapter-8-in-player-s-guide-2nd-edition#post-2681600</link>
				<description></description>
				<pubDate>Tue, 01 Nov 2016 17:06:02 +0000</pubDate>
				<wikidot:authorName>David Moore</wikidot:authorName>								<content:encoded>
					<![CDATA[
						 <p>Dear Mr. Whitaker,</p> <p>In the C# player's guide 2nd edition book, chapter 8, in the Try it Out! section, the student should create a sample program that calculates the radius and height of a cylinder. However, I couldn't figure it out. After I reviewed your sample code, I found the following discrepancies:</p> <p>1- Console.Write() method isn't yet covered in the chapter prior creating the program. How should the student be expected to create a program using a method that wasn't yet covered?</p> <p>2- Converting a string to double isn't just working. When the user input is: five, it says unhandled exception: System.FormatException: Input string was not in a correct format.</p> <p>So what is the point from the convert.ToWhatever() method?</p> <p>Your code is working just fine when the user input is a number. Here is your code sample:</p> <div class="code"> <div class="hl-main"> <pre><span class="hl-identifier">using</span><span class="hl-code"> </span><span class="hl-identifier">System</span><span class="hl-code">; </span><span class="hl-identifier">using</span><span class="hl-code"> </span><span class="hl-identifier">System</span><span class="hl-code">.</span><span class="hl-identifier">Collections</span><span class="hl-code">.</span><span class="hl-identifier">Generic</span><span class="hl-code">; </span><span class="hl-identifier">using</span><span class="hl-code"> </span><span class="hl-identifier">System</span><span class="hl-code">.</span><span class="hl-identifier">Linq</span><span class="hl-code">; </span><span class="hl-identifier">using</span><span class="hl-code"> </span><span class="hl-identifier">System</span><span class="hl-code">.</span><span class="hl-identifier">Text</span><span class="hl-code">; </span><span class="hl-identifier">using</span><span class="hl-code"> </span><span class="hl-identifier">System</span><span class="hl-code">.</span><span class="hl-identifier">Threading</span><span class="hl-code">.</span><span class="hl-identifier">Tasks</span><span class="hl-code">; </span><span class="hl-identifier">namespace</span><span class="hl-code"> </span><span class="hl-identifier">CylinderCalculator</span><span class="hl-code"> </span><span class="hl-brackets">{</span><span class="hl-code"> </span><span class="hl-reserved">class</span><span class="hl-code"> </span><span class="hl-identifier">Program</span><span class="hl-code"> </span><span class="hl-brackets">{</span><span class="hl-code"> </span><span class="hl-types">static</span><span class="hl-code"> </span><span class="hl-types">void</span><span class="hl-code"> </span><span class="hl-identifier">Main</span><span class="hl-brackets">(</span><span class="hl-identifier">string</span><span class="hl-brackets">[]</span><span class="hl-code"> </span><span class="hl-identifier">args</span><span class="hl-brackets">)</span><span class="hl-code"> </span><span class="hl-brackets">{</span><span class="hl-code"> </span><span class="hl-identifier">Console</span><span class="hl-code">.</span><span class="hl-identifier">Write</span><span class="hl-brackets">(</span><span class="hl-quotes">&quot;</span><span class="hl-string">Enter the cylinder's radius: </span><span class="hl-quotes">&quot;</span><span class="hl-brackets">)</span><span class="hl-code">; </span><span class="hl-identifier">string</span><span class="hl-code"> </span><span class="hl-identifier">radiusAsString</span><span class="hl-code"> = </span><span class="hl-identifier">Console</span><span class="hl-code">.</span><span class="hl-identifier">ReadLine</span><span class="hl-brackets">()</span><span class="hl-code">; </span><span class="hl-types">double</span><span class="hl-code"> </span><span class="hl-identifier">radius</span><span class="hl-code"> = </span><span class="hl-identifier">Convert</span><span class="hl-code">.</span><span class="hl-identifier">ToDouble</span><span class="hl-brackets">(</span><span class="hl-identifier">radiusAsString</span><span class="hl-brackets">)</span><span class="hl-code">; </span><span class="hl-identifier">Console</span><span class="hl-code">.</span><span class="hl-identifier">Write</span><span class="hl-brackets">(</span><span class="hl-quotes">&quot;</span><span class="hl-string">Enter the cylinder's height: </span><span class="hl-quotes">&quot;</span><span class="hl-brackets">)</span><span class="hl-code">; </span><span class="hl-identifier">string</span><span class="hl-code"> </span><span class="hl-identifier">heightAsString</span><span class="hl-code"> = </span><span class="hl-identifier">Console</span><span class="hl-code">.</span><span class="hl-identifier">ReadLine</span><span class="hl-brackets">()</span><span class="hl-code">; </span><span class="hl-types">double</span><span class="hl-code"> </span><span class="hl-identifier">height</span><span class="hl-code"> = </span><span class="hl-identifier">Convert</span><span class="hl-code">.</span><span class="hl-identifier">ToDouble</span><span class="hl-brackets">(</span><span class="hl-identifier">heightAsString</span><span class="hl-brackets">)</span><span class="hl-code">; </span><span class="hl-types">double</span><span class="hl-code"> </span><span class="hl-identifier">pi</span><span class="hl-code"> = </span><span class="hl-number">3.1415926</span><span class="hl-code">; </span><span class="hl-types">double</span><span class="hl-code"> </span><span class="hl-identifier">volume</span><span class="hl-code"> = </span><span class="hl-identifier">pi</span><span class="hl-code"> * </span><span class="hl-identifier">radius</span><span class="hl-code"> * </span><span class="hl-identifier">radius</span><span class="hl-code"> * </span><span class="hl-identifier">height</span><span class="hl-code">; </span><span class="hl-types">double</span><span class="hl-code"> </span><span class="hl-identifier">surfaceArea</span><span class="hl-code"> = </span><span class="hl-number">2</span><span class="hl-code"> * </span><span class="hl-identifier">pi</span><span class="hl-code"> * </span><span class="hl-identifier">radius</span><span class="hl-code"> * </span><span class="hl-brackets">(</span><span class="hl-identifier">radius</span><span class="hl-code"> + </span><span class="hl-identifier">height</span><span class="hl-brackets">)</span><span class="hl-code">; </span><span class="hl-identifier">Console</span><span class="hl-code">.</span><span class="hl-identifier">WriteLine</span><span class="hl-brackets">(</span><span class="hl-quotes">&quot;</span><span class="hl-string">The cylinder's volume is: </span><span class="hl-quotes">&quot;</span><span class="hl-code"> + </span><span class="hl-identifier">volume</span><span class="hl-code"> + </span><span class="hl-quotes">&quot;</span><span class="hl-string"> cubic units.</span><span class="hl-quotes">&quot;</span><span class="hl-brackets">)</span><span class="hl-code">; </span><span class="hl-identifier">Console</span><span class="hl-code">.</span><span class="hl-identifier">WriteLine</span><span class="hl-brackets">(</span><span class="hl-quotes">&quot;</span><span class="hl-string">The cylinder's height is: </span><span class="hl-quotes">&quot;</span><span class="hl-code"> + </span><span class="hl-identifier">height</span><span class="hl-code"> + </span><span class="hl-quotes">&quot;</span><span class="hl-string"> square units.</span><span class="hl-quotes">&quot;</span><span class="hl-brackets">)</span><span class="hl-code">; </span><span class="hl-identifier">Console</span><span class="hl-code">.</span><span class="hl-identifier">ReadKey</span><span class="hl-brackets">()</span><span class="hl-code">;</span></pre></div> </div> <p>Appreciate your clarification.</p> 
				 	]]>
				</content:encoded>							</item>
				</channel>
</rss>