{"id":4329,"date":"2020-09-01T00:01:34","date_gmt":"2020-09-01T07:01:34","guid":{"rendered":"https:\/\/c-for-dummies.com\/blog\/?p=4329"},"modified":"2020-09-08T08:38:07","modified_gmt":"2020-09-08T15:38:07","slug":"spelling-numbers","status":"publish","type":"post","link":"https:\/\/c-for-dummies.com\/blog\/?p=4329","title":{"rendered":"Spelling Numbers"},"content":{"rendered":"<p>I would guess that most beginning programmers can deftly craft a loop that outputs sequential integer values, say from 0 to 100. In fact, this is the type of code I write whenever I learn a new language. I asked myself, &#8220;Can I write a loop to output values 0 to 100?&#8221; Usually in no time, I&#8217;ve constructed such a program. Simple.<br \/>\n<!--more--><br \/>\nOf course, when you code a loop in any language, you generate numeric output. Programming languages naturally output values, offering you a choice of bases: decimal, octal, hexadecimal, and some may even offer binary. Not one that I know of, however, outputs values in English (or whatever your mother tongue may be).<\/p>\n<p>Your task for this month&#8217;s Exercise is to code the <em>verbal()<\/em> function. Its argument is an integer value in the range of 0 to 100. Its return value is a string representing the word(s) for the number input.<\/p>\n<p>For example, if you send the <em>verbal()<\/em> function the integer value 26, it returns the text &#8220;twenty six.&#8221;<\/p>\n<p>Here is a code skeleton to get started:<\/p>\n<h3><a href=\"https:\/\/github.com\/dangookin\/C-For-Dummies-Blog\/blob\/master\/2020_09_01-Exercise-skeleton.c\" rel=\"noopener noreferrer\" target=\"_blank\">2020_09_01-Exercise-skeleton.c<\/a><\/h3>\n<pre class=\"screen\">\r\n#include &lt;stdio.h&gt;\r\n\r\n<span class=\"comments\">\/* return string representing integers 0 through 100 *\/<\/span>\r\nchar *verbal(int n)\r\n{\r\n}\r\n\r\nint main()\r\n{\r\n    int x;\r\n\r\n    for(x=0; x&lt;=100; x++ )\r\n        printf(\"%s\\n\",verbal(x));\r\n\r\n    return(0);\r\n}<\/pre>\n<p>Complete the <em>verbal()<\/em> function &mdash; and be clever with your solution! Yes, it&#8217;s possible to code a string array that lists all output values: <code>zero<\/code> to <code>one hundred<\/code>. Don&#8217;t do that! True, you must code string values for the digits, but be frugal. After all, in the string output of values from 0 to 100 a lot text is repeated.<\/p>\n<p><a href=\"https:\/\/c-for-dummies.com\/blog\/wp-content\/uploads\/2020\/09\/verbal_output.txt\">Click here<\/a> to view the output from my solution&#8217;s sample run. <a href=\"https:\/\/c-for-dummies.com\/blog\/?p=4342\">Click <em>here<\/em><\/a> to view my solution, but please try this Exercise on your own before checking to see what I&#8217;ve done.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Any program can output digits, but how about a program that outputs the names of the numbers? <a href=\"https:\/\/c-for-dummies.com\/blog\/?p=4329\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[],"class_list":["post-4329","post","type-post","status-publish","format-standard","hentry","category-exercise"],"_links":{"self":[{"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/4329","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=4329"}],"version-history":[{"count":7,"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/4329\/revisions"}],"predecessor-version":[{"id":4363,"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/4329\/revisions\/4363"}],"wp:attachment":[{"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=4329"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=4329"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=4329"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}