{"id":264,"date":"2009-07-28T14:06:28","date_gmt":"2009-07-28T13:06:28","guid":{"rendered":"http:\/\/www.codingfriends.com\/index.php\/2009\/07\/28\/add-two-numbers-5\/"},"modified":"2009-07-28T14:06:28","modified_gmt":"2009-07-28T13:06:28","slug":"add-two-numbers-5","status":"publish","type":"post","link":"https:\/\/www.codingfriends.com\/index.php\/2009\/07\/28\/add-two-numbers-5\/","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>The gets function is able to get a string from the console input, with the string inputted this allows the string function .to_i (to_integer) conversion for the answer to add up to integer values.<\/p>\n<p>The code <\/p>\n<pre lang=\"ruby\">\r\nprint \"Please enter number 1 : \";\r\n# get the input from the console, \r\nval1 = gets;\r\nprint \"Please enter number 2 : \";\r\nval2 = gets;\r\n# convert the string console inputs to_i (to_integers) and add together\r\nprint \"Answer : \" , (val1.to_i + val2.to_i), \"\\n\";  \r\n<\/pre>\n<p>save that as addtwonumbers.rb.<\/p>\n<p>To run ruby addtwonumbers.rb, and the output would be similar to <\/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. The gets function is able to get a string from the console input, with the string inputted this allows the string function .to_i &hellip; <a href=\"https:\/\/www.codingfriends.com\/index.php\/2009\/07\/28\/add-two-numbers-5\/\" 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":[20],"tags":[8,398,404,400],"class_list":["post-264","post","type-post","status-publish","format-standard","hentry","category-ruby","tag-gnu","tag-linux","tag-ruby","tag-windows"],"_links":{"self":[{"href":"https:\/\/www.codingfriends.com\/index.php\/wp-json\/wp\/v2\/posts\/264","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=264"}],"version-history":[{"count":0,"href":"https:\/\/www.codingfriends.com\/index.php\/wp-json\/wp\/v2\/posts\/264\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.codingfriends.com\/index.php\/wp-json\/wp\/v2\/media?parent=264"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.codingfriends.com\/index.php\/wp-json\/wp\/v2\/categories?post=264"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.codingfriends.com\/index.php\/wp-json\/wp\/v2\/tags?post=264"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}