{"id":166,"date":"2009-07-24T22:12:53","date_gmt":"2009-07-24T21:12:53","guid":{"rendered":"http:\/\/www.codingfriends.com\/?p=166"},"modified":"2009-07-24T22:12:53","modified_gmt":"2009-07-24T21:12:53","slug":"add-two-numbers","status":"publish","type":"post","link":"https:\/\/www.codingfriends.com\/index.php\/2009\/07\/24\/add-two-numbers\/","title":{"rendered":"Add two numbers"},"content":{"rendered":"<p>This tutorial will demonstrate how to read from the input console (console line) to answer the prompts.  The prompts will need to be a integer value to add the two inputs together.<\/p>\n<p>I am using the System.Console object to read from the console and then converting the string inputs into integers with the Convert.ToInt32 function (the System.Convert has many methods and ToInt32 is one of these).<\/p>\n<p>The code <\/p>\n<pre lang=\"csharp\">\r\nusing System;       \/\/ for the console object\r\n\r\nclass addtwonumbers\r\n{\r\n       public static void Main()\r\n       {\r\n              try \r\n              {\r\n                     \/\/ output to the console\r\n                     Console.Write(\"Please enter value 1 : \");\r\n                     \/\/ readin the console input, and then convert to a integer value\r\n                     int val1 = Convert.ToInt32(Console.ReadLine());\r\n                     Console.Write(\"Please enter value 2 : \");\r\n                     int val2 = Convert.ToInt32(Console.ReadLine());\r\n                     \/\/ write out the answer \r\n                     Console.WriteLine(\"Answer = \" + (val1 + val2));\r\n              }\r\n              catch (Exception e)\r\n              {\r\n                     \/\/ any errors. Like converting a string to a integer value\r\n                     Console.WriteLine(\"Error : \" + e.ToString());\r\n              }\r\n       }\r\n}\r\n<\/pre>\n<p>save that as addtwonumbers.cs.<\/p>\n<p>Once compiled (mcp addtwonumbers.cs with mono) and executed (mono addtwonumbers.exe) the output will be<\/p>\n<pre class=\"consoleoutput\">\r\nPlease enter value 1 : 30\r\nPlease enter value 2: 23\r\nAnswer = 53\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>This tutorial will demonstrate how to read from the input console (console line) to answer the prompts. The prompts will need to be a integer value to add the two inputs together. I am using the System.Console object to read from the console and then converting the string inputs into integers with the Convert.ToInt32 function &hellip; <a href=\"https:\/\/www.codingfriends.com\/index.php\/2009\/07\/24\/add-two-numbers\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Add two numbers<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[12],"tags":[14,398,13,400],"class_list":["post-166","post","type-post","status-publish","format-standard","hentry","category-c_sharp","tag-c-sharp","tag-linux","tag-mono","tag-windows"],"_links":{"self":[{"href":"https:\/\/www.codingfriends.com\/index.php\/wp-json\/wp\/v2\/posts\/166","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.codingfriends.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.codingfriends.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.codingfriends.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.codingfriends.com\/index.php\/wp-json\/wp\/v2\/comments?post=166"}],"version-history":[{"count":1,"href":"https:\/\/www.codingfriends.com\/index.php\/wp-json\/wp\/v2\/posts\/166\/revisions"}],"predecessor-version":[{"id":167,"href":"https:\/\/www.codingfriends.com\/index.php\/wp-json\/wp\/v2\/posts\/166\/revisions\/167"}],"wp:attachment":[{"href":"https:\/\/www.codingfriends.com\/index.php\/wp-json\/wp\/v2\/media?parent=166"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.codingfriends.com\/index.php\/wp-json\/wp\/v2\/categories?post=166"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.codingfriends.com\/index.php\/wp-json\/wp\/v2\/tags?post=166"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}