{"id":781,"date":"2017-08-13T15:44:35","date_gmt":"2017-08-13T15:44:35","guid":{"rendered":"http:\/\/people.utm.my\/kohmenghock\/?page_id=781"},"modified":"2017-08-14T03:49:41","modified_gmt":"2017-08-14T03:49:41","slug":"codeblocks-simple-guide-requesting-input-from-user","status":"publish","type":"page","link":"https:\/\/people.utm.my\/kohmenghock\/codeblocks-simple-guide-requesting-input-from-user\/","title":{"rendered":"Code::Blocks simple guide &#8211; Requesting input from user"},"content":{"rendered":"<p style=\"text-align: justify\"><span style=\"font-size: 12pt;font-family: arial,helvetica,sans-serif\"><br \/>\nWhen running the code, we need to inputs for the calculations. \u00a0This will be provided by the user. There are two ways in which input values can be passed on to the code. One is to store the relevant input values in a file and to read those values. The second option is to write a short print statement to request inputs from user over the terminal. \u00a0We will look at the latter option here. In any case, both options make use of the read statement.<br \/>\n<\/span><\/p>\n<p style=\"text-align: justify\"><span style=\"font-size: 12pt;font-family: arial,helvetica,sans-serif\"><br \/>\nLets say we want to store the value provided by the user into a variable named as &#8220;mass&#8217;. We will first print a statement to request user to provide a value for mass by:<\/span><\/p>\n<p style=\"text-align: center\"><span style=\"font-size: 12pt;font-family: arial,helvetica,sans-serif\"><strong>print*, &#8220;Provide a value for mass (in unit of kilogram).&#8221;<\/strong><\/span><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\"><span style=\"font-size: 12pt;font-family: arial,helvetica,sans-serif\">In the subsequent line, we will use the read statement such as:<\/span><\/p>\n<p style=\"text-align: center\"><span style=\"font-size: 12pt;font-family: arial,helvetica,sans-serif\"><strong>read*, mass<\/strong><\/span><\/p>\n<p style=\"text-align: justify\"><span style=\"font-size: 12pt;font-family: arial,helvetica,sans-serif\"><br \/>\nand the value provided by the user will be stored in a variable called &#8220;mass&#8221;.<br \/>\n<\/span><\/p>\n<p style=\"text-align: justify\"><span style=\"font-size: 12pt;font-family: arial,helvetica,sans-serif\"><br \/>\nIn the example of code provided <span style=\"color: #ff0000\"><a href=\"https:\/\/people.utm.my\/kohmenghock\/example-of-read-statement-from-users-input\/\" target=\"_blank\" rel=\"noopener\">here<\/a><\/span>, I have make use of the read statement to obtain input values for mass and velocity, and use these values to calculate momentum. You may want to practice this to compute any other values. After the momentum has been calculated, the result is then printed on the terminal using a formatted print statement. A short discussion on formatted print (also applicable to write) statement can be found <span style=\"color: #3366ff\"><a href=\"https:\/\/people.utm.my\/kohmenghock\/codeblocks-simple-guide-requesting-input-from-user\/codeblocks-simple-guide-formatted-print-statement\/\" target=\"_blank\" rel=\"noopener\">here<\/a><\/span>.<br \/>\n<\/span><\/p>\n<p style=\"text-align: justify\"><span style=\"font-size: 12pt;font-family: arial,helvetica,sans-serif\"><br \/>\nAnother example of a Fortran code that makes use of the techniques discussed earlier is included here for calculating the <a href=\"https:\/\/people.utm.my\/kohmenghock\/example-of-fortran-code-kinetic-energy\/\" target=\"_blank\" rel=\"noopener\">kinetic energy<\/a> of an object.<br \/>\n<\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>When running the code, we need to inputs for the calculations. \u00a0This will be provided by the user. There are two ways in which input values can be passed on to the code. One is to store the relevant input values in a file and to read those values. The second option is to write &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/people.utm.my\/kohmenghock\/codeblocks-simple-guide-requesting-input-from-user\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Code::Blocks simple guide &#8211; Requesting input from user&#8221;<\/span><\/a><\/p>\n","protected":false},"author":14180,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"open","template":"","meta":{"footnotes":""},"class_list":["post-781","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/people.utm.my\/kohmenghock\/wp-json\/wp\/v2\/pages\/781","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/people.utm.my\/kohmenghock\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/people.utm.my\/kohmenghock\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/people.utm.my\/kohmenghock\/wp-json\/wp\/v2\/users\/14180"}],"replies":[{"embeddable":true,"href":"https:\/\/people.utm.my\/kohmenghock\/wp-json\/wp\/v2\/comments?post=781"}],"version-history":[{"count":0,"href":"https:\/\/people.utm.my\/kohmenghock\/wp-json\/wp\/v2\/pages\/781\/revisions"}],"wp:attachment":[{"href":"https:\/\/people.utm.my\/kohmenghock\/wp-json\/wp\/v2\/media?parent=781"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}