Note that there are some explanatory texts on larger screens.

plurals
  1. POC++ program stops responding on execution
    text
    copied!<p>Basic information regarding my computer: Windows 7 x64 OS<br> 8gb RAM<br> Using MingW compiler </p> <p>So, everytime I run my program through the terminal after compiling it, it immediately stops responding. I can't seem to find the problem myself, so I'm asking for an extra set of eyes to point it out for me. I'm practically a beginner at C++ at the moment, so bear with me.</p> <pre><code> #include &lt;iostream&gt; #include &lt;cstdlib&gt; #include &lt;string&gt; #include &lt;vector&gt; #include &lt;ctime&gt; using namespace std; int main() { bool correct = false; srand(time(NULL)); vector&lt;string&gt; guess; vector&lt;string&gt; pallete; vector&lt;string&gt; secret; pallete.push_back("red"); pallete.push_back("green"); pallete.push_back("blue"); pallete.push_back("yellow"); for(int i = 0; i &lt; 4 ; i++) { secret.push_back(pallete.at(rand()%secret.size())); } for(int j = 0; j &lt; 4 ; j++) { guess.push_back(pallete.at(rand()%guess.size())); } vector&lt;string&gt; secretMem = secret; cout &lt;&lt; "the guess was:"; for(int x = 0; x&lt;4; x++) { cout &lt;&lt; guess[x] &lt;&lt; endl; } while(correct == false) { int blackP = 0; int whiteP = 0; secret = secretMem; for (int idxB = 0; idxB &lt; secret.size(); idxB++) { if (guess[idxB] == secret[idxB]) { secret[idxB] = "0"; guess[idxB] = "1"; blackP++; } } for (int idxW = 0; idxW &lt; secret.size(); idxW++) for (int idyW = 0; idyW &lt; guess.size(); idyW++) { if (secret[idxW] == guess[idyW]) { secret[idxW] = "0"; guess[idxW] = "1"; whiteP++; } } if (blackP == 4) { cout &lt;&lt; "Congratulations you win." &lt;&lt; endl &lt;&lt; "The secret code was:"&lt;&lt; endl; for(int y = 0; y&lt;4; y++) { cout &lt;&lt; secretMem[y] &lt;&lt; endl; } correct = true; } else cout &lt;&lt; "you scored: " &lt;&lt; blackP &lt;&lt; " Black pegs" &lt;&lt; "and" &lt;&lt; whiteP &lt;&lt; " White pegs" &lt;&lt; endl; } return 0; } </code></pre> <p>Also.... What is with this horrible code formatting.... I just can't get things to line up properly in the preview like it is when I'm writing it....</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