Note that there are some explanatory texts on larger screens.

plurals
  1. POC++ program crashes in the while loop when asked to use random number generator
    text
    copied!<p>So I am trying to make a program which will generate random basic mathematical questions like addition, subtraction, etc.</p> <p>While I am trying to generate division questions I made a do-while loop which runs until the prerequisite is met for division quesions.</p> <p>But for some reason when I ask it to generate 20 division questions with none with remainder it always crashes.</p> <p>Please help</p> <p>Here's the code</p> <pre><code>#include &lt;iostream&gt; #include &lt;cstdlib&gt; #include &lt;ctime&gt; using namespace std; int correct,total,MAXVAL; const char oper[4]={'/','/','/','/'}; typedef struct data{ int first,second; char operation; }data; data datagenerator(){ data newData; newData.first= (rand()%MAXVAL); newData.operation=oper[rand()%4]; newData.second=(rand()%MAXVAL); return newData; } bool corrector(data newData){ bool isture=false; switch(newData.operation){ case '/': if((newData.first%newData.second)==0){ isture=true; } break; case '*': isture=true; break; case '+': isture=true; break; case '-': isture=true; break; } return isture; } void quizer(){ system("CLS"); for(int counter=1;counter&lt;=total;counter++){ cout&lt;&lt;"Q"&lt;&lt;counter&lt;&lt;": "; data newData; do{ newData=datagenerator(); }while(!corrector(newData)); cout&lt;&lt;newData.first&lt;&lt;newData.operation&lt;&lt;newData.second&lt;&lt;"\n"; } cout&lt;&lt;"\nYou got "&lt;&lt;correct&lt;&lt;"/"&lt;&lt;total&lt;&lt;"correct\n"; } int main(){ //srand((unsigned)time(0)); char x; cout&lt;&lt;"How many questions do you want?"&lt;&lt;endl; cin&gt;&gt;total; cout&lt;&lt;"Enter the maximum value\n"; cin&gt;&gt;MAXVAL; cout&lt;&lt;"Are you ready?\n"; cin&gt;&gt;x; quizer(); system("PAUSE"); return 0; } </code></pre>
 

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