Note that there are some explanatory texts on larger screens.

plurals
  1. POC++ Ways to shut down a program
    text
    copied!<p>Before you start wasting your time on me, please keep in mind that this question is more about knowing if this shutdown is legit enough.</p> <p>Alright.</p> <p>I read all kinds of ways to shut down a program. I KNOW that it's always best to shut down the program, at the end! So as i said, i read all kinds of topics, but i couldn't really find one that i understood correctly. So i kinda came up with my own way. I just want to make sure it's an okay method.</p> <pre><code>int main() { cout &lt;&lt; "Welcome to my fantastic program!" &lt;&lt; endl; cout &lt;&lt; "You're the first one to experience my command program!" &lt;&lt; endl; cout &lt;&lt; "Let's try with a simple command. Try typing help" &lt;&lt; endl; while (running == 1) { commands(); if (running == 0) { exit(0); } } return 0; } </code></pre> <p>So i want you to focus on the while loop. This is my method.</p> <pre><code>void commands() { cin &gt;&gt; command; if (command == "help") { cout &lt;&lt; "-------------------------------" &lt;&lt; endl; cout &lt;&lt; "-this is the &lt;HELP&gt; section----" &lt;&lt; endl; cout &lt;&lt; "-exit (exits the program.)" &lt;&lt; endl; cout &lt;&lt; "-Stay tuned for more commands--" &lt;&lt; endl; cout &lt;&lt; "-------------------------------" &lt;&lt; endl; } else if (command == "exit") { running = 0; } else { cout &lt;&lt; "The command does not exist: " &lt;&lt; command &lt;&lt; endl; } } </code></pre> <p>And this is my command function. As you see, this changes "running" to 0 (or false). I hope i made this understandable enough. </p> <p>Thanks.</p> <p>EDIT: All i want to know is, if this is an okay method :)</p> <p>FINAL EDIT: Alright! I changed "exit(0);" to "return(0);". So i guess this is a okay good method! Thanks for your help! :)</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload