{"id":8419,"date":"2022-09-13T13:00:54","date_gmt":"2022-09-13T07:30:54","guid":{"rendered":"https:\/\/jassweb.com\/solved\/solved-why-is-my-program-not-working-closed\/"},"modified":"2022-09-13T13:00:54","modified_gmt":"2022-09-13T07:30:54","slug":"solved-why-is-my-program-not-working-closed","status":"publish","type":"post","link":"https:\/\/jassweb.com\/solved\/solved-why-is-my-program-not-working-closed\/","title":{"rendered":"[Solved] Why is My Program not Working [closed]"},"content":{"rendered":"<p> [ad_1]<br \/>\n<\/p>\n<div id=\"answer-30953519\" class=\"answer js-answer accepted-answer js-accepted-answer\" data-answerid=\"30953519\" data-parentid=\"30912551\" data-score=\"0\" data-position-on-page=\"2\" data-highest-scored=\"1\" data-question-has-accepted-highest-score=\"1\" itemprop=\"acceptedAnswer\" itemscope itemtype=\"https:\/\/schema.org\/Answer\">\n<div class=\"post-layout\">\n<div class=\"votecell post-layout--left\"><\/div>\n<div class=\"answercell post-layout--right\">\n<div class=\"s-prose js-post-body\" itemprop=\"text\">\n<p><strong><em>EUREKA!!!!!!<\/em><\/strong><\/p>\n<p>I finally came up with a working solution. No more errors. I&#8217;m calling it version 2.0.0<br \/>\nI&#8217;ve uploaded it online, and here&#8217;s the link<\/p>\n<p>[version 2.0.0] <a rel=\"nofollow noopener\" target=\"_blank\" href=\"http:\/\/mibpaste.com\/3NADgl\">http:\/\/mibpaste.com\/3NADgl<\/a> <\/p>\n<p>All that&#8217;s left is to go to excel, and derive the final states of the door and be sure, that it&#8217;s working perfectly. Please take a look at my solution, and comment on any error that I may have made, or any way you think that I may optimize the code.I thank you for your help, it allowed me to redesign a working solution to the program. I&#8217;m sstarting to think that an Out-of-bounds error, might have caused my version 1 to crash, but the logic was flawed, anyway, so I&#8217;m scrapping it.<\/p>\n<p>This is ths code:<\/p>\n<pre><code>\/**********************************************************************************************\n200 DOOR PROGRAM\nVersion 2.0.0\nAuthor: Alafin OluwaTobi Department of Computer Science, Babcock University\nNew Additions: I redrew, the algorithm, to geneate a more logically viable solution,\nI additionally, expanded the size of the array, to prevent a potential out of bounds error.\n**********************************************************************************************\/\n\n\/\/Hello. This a program,I've written to solve a fun mental problem.\n\/\/I'll include a full explanation of the problem, below.\n\n\/**********************************************************************************************\n    *You are in a Hallway, filled with 200 doors . \n    *ALL the doors are initially closed . \n    *You walk along the corridor, *BACK* and *FORTH* reversing the state of every door which you stop at .\n    *I.e if it is open, you close it .\n    *If it is closed,  you open it .\n    *On every nth trip, you stop at every nth door .\n    *I.e on your first trip, you stop at every door. On your second trip every second door, On your third trip every third door, etc .\n\n*Write a program to display the final state of the doors .\n**********************************************************************************************\/\n\n\/**********************************************************************************************\n                                        SOLUTION\n    *NOTE: on even trips, your coming back, while on odd trips your going forwards .\n    *2 Imaginary doors, door 0 and 201, delimit the corridor .\n    *On odd trips, the doors stopped at will be (0+n) doors .\n    *I.e you will be counting forward, in (0+n) e.g say, n = 5: 5, 10, 15, 20, 25\n    *On even trips, the doors stopped at will be (201-n) doors.\n    *I.e you will be counting backwards in (201-n) say n = 4: 197, 193, 189, 185, 181\n**********************************************************************************************\/\n\n#include &lt;iostream&gt;\n#include &lt;cstdlib&gt;  \/\/Including the basic libraries\n\nbool HALLWAY [202] ; \n\/*\n    *Declaring the array, for the Hallway, as global in order to initialise all the elements at zero.\n    *In addition,the size is set at 202 to make provision for the delimiting imaginary doors, \n    *This also serves to prevent potential out of bound errors, that may occur, in the use of thefor looplater on.\n*\/\n\ninline void inverse (bool args []) ;\n\/*\n    *Prototyping the function, which will be used to reverse the states of the door.\n    *The function, has been declared as inline in order to allow faster compilation, and generate a faster executable program.\n*\/\n\nusing namespace std ;   \/\/Using the standard namespace\n\nint main ()\n{\n    inverse (HALLWAY) ; \/\/Calling the inverse function, to act on the Hallway, reversing the doors.\n\n    cout &lt;&lt; \"\\t\\t\\t\\t\\t\\t\\t\\t\\t\\t200 DOOR TABLE\\n\" ;\n\n    for(int i = 1 ; i &lt;= 200 ; i++ )\n    \/\/A loop to display the states of the doors.\n    {\n        if (HALLWAY [i] == 0) \n        \/\/The if construct allows us to print out the state of the door as closed, when the corresponding element of the Array has a value of zero.\n        {\n            cout &lt;&lt; \"DOOR \" &lt;&lt; i &lt;&lt; \" is\\tCLOSED\" &lt;&lt; endl ;\n            for (int z = 0 ; z &lt;= 300 ; z++)\n                cout &lt;&lt; \"_\" ;\n            cout &lt;&lt; \"\\n\" ;\n        }\n\n        else if (HALLWAY [i] == 1)\n        \/\/The else if construct allows us to print out the state of the door as open, when the corresponding element of the Array has a value of one.\n        {\n            cout &lt;&lt; \"DOOR \" &lt;&lt; i &lt;&lt; \" is\\tOPEN\" &lt;&lt; endl ;\n            for (int z = 0 ; z &lt;= 300 ; z++)\n                cout &lt;&lt; \"_\" ;\n            cout &lt;&lt; \"\\n\" ;\n        }\n    } \n\nreturn 0 ; \/\/Returns the value of zero, to show that the program executed properly\n}\n\nvoid inverse (bool args[])`\n\n{\n\n    for ( int n = 1; n &lt;= 200 ; n++)\n\n    \/\/This loop, is to control the individual trips, i.e trip 1, 2, 3, etc..\n\n    {\n\n        if (n%2 == 0)\n        \/\/This if construct, is to ensure that on even numbers(i,e n%2 = 0), that you are coming down the hallway and counting backwards\n    {\n            for (int b = (201-n) ; b &lt;= 200 &amp;&amp; b &gt;= 1 ; b -= n)\n            \/*\n                *This loop, is for the doors that you stop at on your nth trip. \n                *The door is represented by the variable b.\n                *Because you are coming back, b will be reducing proportionally, in n.\n                *The Starting value for b on your nth trip, will be (201-n)\n                * {b -= n} takes care of this. On the second turn for example. First value of b will be 199, 197, 195, 193, ..., 1\n            *\/\n                args [b] = !(args [b]) ;\n                \/\/This is the actual reversal operation, which reverses the state of the door.\n       }\n\n        else if (n%2 != 0)\n        \/\/This else if construct, is to ensure that on odd numbers(i.e n%2 != 0), that you are going up the hallway and counting forwards\n        {\n            for (int b = n ; b &lt;= 200 &amp;&amp; b &gt;= 1 ; b += n)\n            \/*\n                *This loop, is for the doors that you stop at on your nth trip. \n                *The door is represented by the variable b.\n                *Because you are going forwards, b will be increasing proportionally, in n.\n                *The starting value of b will be (0+n) whch is equal to n\n                * {b += n} takes care of this. On the third turn for example. First value of b will be 3, 6, 9, 12, ...., 198\n            *\/\n                args [b] = !(args [b]) ;\n                \/\/This is the actual reversal operation, which reverses the state of the door\n        }\n    }\n}\n<\/code><\/pre>\n<\/p><\/div>\n<div class=\"mt24\"><\/div>\n<\/div>\n<p>            <span class=\"d-none\" itemprop=\"commentCount\"><\/span> <\/p><\/div>\n<\/div>\n<p>[ad_2]<\/p>\n<p>solved Why is My Program not Working [closed] <\/p>\n","protected":false},"excerpt":{"rendered":"<p>[ad_1] EUREKA!!!!!! I finally came up with a working solution. No more errors. I&#8217;m calling it version 2.0.0 I&#8217;ve uploaded it online, and here&#8217;s the link [version 2.0.0] http:\/\/mibpaste.com\/3NADgl All that&#8217;s left is to go to excel, and derive the final states of the door and be sure, that it&#8217;s working perfectly. Please take a &#8230; <a title=\"[Solved] Why is My Program not Working [closed]\" class=\"read-more\" href=\"https:\/\/jassweb.com\/solved\/solved-why-is-my-program-not-working-closed\/\" aria-label=\"More on [Solved] Why is My Program not Working [closed]\">Read more<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[320],"tags":[324],"class_list":["post-8419","post","type-post","status-publish","format-standard","hentry","category-solved","tag-c"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>[Solved] Why is My Program not Working [closed] - JassWeb<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/jassweb.com\/solved\/solved-why-is-my-program-not-working-closed\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"[Solved] Why is My Program not Working [closed] - JassWeb\" \/>\n<meta property=\"og:description\" content=\"[ad_1] EUREKA!!!!!! I finally came up with a working solution. No more errors. I&#8217;m calling it version 2.0.0 I&#8217;ve uploaded it online, and here&#8217;s the link [version 2.0.0] http:\/\/mibpaste.com\/3NADgl All that&#8217;s left is to go to excel, and derive the final states of the door and be sure, that it&#8217;s working perfectly. Please take a ... Read more\" \/>\n<meta property=\"og:url\" content=\"https:\/\/jassweb.com\/solved\/solved-why-is-my-program-not-working-closed\/\" \/>\n<meta property=\"og:site_name\" content=\"JassWeb\" \/>\n<meta property=\"article:published_time\" content=\"2022-09-13T07:30:54+00:00\" \/>\n<meta name=\"author\" content=\"Kirat\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Kirat\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"5 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/jassweb.com\/solved\/solved-why-is-my-program-not-working-closed\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/jassweb.com\/solved\/solved-why-is-my-program-not-working-closed\/\"},\"author\":{\"name\":\"Kirat\",\"@id\":\"https:\/\/jassweb.com\/solved\/#\/schema\/person\/65c9c7b7958150c0dc8371fa35dd7c31\"},\"headline\":\"[Solved] Why is My Program not Working [closed]\",\"datePublished\":\"2022-09-13T07:30:54+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/jassweb.com\/solved\/solved-why-is-my-program-not-working-closed\/\"},\"wordCount\":151,\"publisher\":{\"@id\":\"https:\/\/jassweb.com\/solved\/#organization\"},\"keywords\":[\"c++\"],\"articleSection\":[\"Solved\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/jassweb.com\/solved\/solved-why-is-my-program-not-working-closed\/\",\"url\":\"https:\/\/jassweb.com\/solved\/solved-why-is-my-program-not-working-closed\/\",\"name\":\"[Solved] Why is My Program not Working [closed] - JassWeb\",\"isPartOf\":{\"@id\":\"https:\/\/jassweb.com\/solved\/#website\"},\"datePublished\":\"2022-09-13T07:30:54+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/jassweb.com\/solved\/solved-why-is-my-program-not-working-closed\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/jassweb.com\/solved\/solved-why-is-my-program-not-working-closed\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/jassweb.com\/solved\/solved-why-is-my-program-not-working-closed\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/jassweb.com\/solved\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"[Solved] Why is My Program not Working [closed]\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/jassweb.com\/solved\/#website\",\"url\":\"https:\/\/jassweb.com\/solved\/\",\"name\":\"JassWeb\",\"description\":\"Build High-quality Websites\",\"publisher\":{\"@id\":\"https:\/\/jassweb.com\/solved\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/jassweb.com\/solved\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/jassweb.com\/solved\/#organization\",\"name\":\"Jass Web\",\"url\":\"https:\/\/jassweb.com\/solved\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/jassweb.com\/solved\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/jassweb.com\/wp-content\/uploads\/2021\/02\/jass-website-logo-1.png\",\"contentUrl\":\"https:\/\/jassweb.com\/wp-content\/uploads\/2021\/02\/jass-website-logo-1.png\",\"width\":693,\"height\":132,\"caption\":\"Jass Web\"},\"image\":{\"@id\":\"https:\/\/jassweb.com\/solved\/#\/schema\/logo\/image\/\"}},{\"@type\":\"Person\",\"@id\":\"https:\/\/jassweb.com\/solved\/#\/schema\/person\/65c9c7b7958150c0dc8371fa35dd7c31\",\"name\":\"Kirat\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/jassweb.com\/solved\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/jassweb.com\/solved\/wp-content\/litespeed\/avatar\/1261af3c9451399fa1336d28b98ea3bb.jpg?ver=1775798750\",\"contentUrl\":\"https:\/\/jassweb.com\/solved\/wp-content\/litespeed\/avatar\/1261af3c9451399fa1336d28b98ea3bb.jpg?ver=1775798750\",\"caption\":\"Kirat\"},\"sameAs\":[\"http:\/\/jassweb.com\"],\"url\":\"https:\/\/jassweb.com\/solved\/author\/jaspritsinghghumangmail-com\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"[Solved] Why is My Program not Working [closed] - JassWeb","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/jassweb.com\/solved\/solved-why-is-my-program-not-working-closed\/","og_locale":"en_US","og_type":"article","og_title":"[Solved] Why is My Program not Working [closed] - JassWeb","og_description":"[ad_1] EUREKA!!!!!! I finally came up with a working solution. No more errors. I&#8217;m calling it version 2.0.0 I&#8217;ve uploaded it online, and here&#8217;s the link [version 2.0.0] http:\/\/mibpaste.com\/3NADgl All that&#8217;s left is to go to excel, and derive the final states of the door and be sure, that it&#8217;s working perfectly. Please take a ... Read more","og_url":"https:\/\/jassweb.com\/solved\/solved-why-is-my-program-not-working-closed\/","og_site_name":"JassWeb","article_published_time":"2022-09-13T07:30:54+00:00","author":"Kirat","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Kirat","Est. reading time":"5 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/jassweb.com\/solved\/solved-why-is-my-program-not-working-closed\/#article","isPartOf":{"@id":"https:\/\/jassweb.com\/solved\/solved-why-is-my-program-not-working-closed\/"},"author":{"name":"Kirat","@id":"https:\/\/jassweb.com\/solved\/#\/schema\/person\/65c9c7b7958150c0dc8371fa35dd7c31"},"headline":"[Solved] Why is My Program not Working [closed]","datePublished":"2022-09-13T07:30:54+00:00","mainEntityOfPage":{"@id":"https:\/\/jassweb.com\/solved\/solved-why-is-my-program-not-working-closed\/"},"wordCount":151,"publisher":{"@id":"https:\/\/jassweb.com\/solved\/#organization"},"keywords":["c++"],"articleSection":["Solved"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/jassweb.com\/solved\/solved-why-is-my-program-not-working-closed\/","url":"https:\/\/jassweb.com\/solved\/solved-why-is-my-program-not-working-closed\/","name":"[Solved] Why is My Program not Working [closed] - JassWeb","isPartOf":{"@id":"https:\/\/jassweb.com\/solved\/#website"},"datePublished":"2022-09-13T07:30:54+00:00","breadcrumb":{"@id":"https:\/\/jassweb.com\/solved\/solved-why-is-my-program-not-working-closed\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/jassweb.com\/solved\/solved-why-is-my-program-not-working-closed\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/jassweb.com\/solved\/solved-why-is-my-program-not-working-closed\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/jassweb.com\/solved\/"},{"@type":"ListItem","position":2,"name":"[Solved] Why is My Program not Working [closed]"}]},{"@type":"WebSite","@id":"https:\/\/jassweb.com\/solved\/#website","url":"https:\/\/jassweb.com\/solved\/","name":"JassWeb","description":"Build High-quality Websites","publisher":{"@id":"https:\/\/jassweb.com\/solved\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/jassweb.com\/solved\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/jassweb.com\/solved\/#organization","name":"Jass Web","url":"https:\/\/jassweb.com\/solved\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/jassweb.com\/solved\/#\/schema\/logo\/image\/","url":"https:\/\/jassweb.com\/wp-content\/uploads\/2021\/02\/jass-website-logo-1.png","contentUrl":"https:\/\/jassweb.com\/wp-content\/uploads\/2021\/02\/jass-website-logo-1.png","width":693,"height":132,"caption":"Jass Web"},"image":{"@id":"https:\/\/jassweb.com\/solved\/#\/schema\/logo\/image\/"}},{"@type":"Person","@id":"https:\/\/jassweb.com\/solved\/#\/schema\/person\/65c9c7b7958150c0dc8371fa35dd7c31","name":"Kirat","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/jassweb.com\/solved\/#\/schema\/person\/image\/","url":"https:\/\/jassweb.com\/solved\/wp-content\/litespeed\/avatar\/1261af3c9451399fa1336d28b98ea3bb.jpg?ver=1775798750","contentUrl":"https:\/\/jassweb.com\/solved\/wp-content\/litespeed\/avatar\/1261af3c9451399fa1336d28b98ea3bb.jpg?ver=1775798750","caption":"Kirat"},"sameAs":["http:\/\/jassweb.com"],"url":"https:\/\/jassweb.com\/solved\/author\/jaspritsinghghumangmail-com\/"}]}},"_links":{"self":[{"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/posts\/8419","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/comments?post=8419"}],"version-history":[{"count":0,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/posts\/8419\/revisions"}],"wp:attachment":[{"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/media?parent=8419"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/categories?post=8419"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/tags?post=8419"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}