Help Me! Why is this stopping ?
I recently was trying to create a solver for Agus Mei's Quiz No. 3, 100. So, I created this: #include<bits/stdc++.h> using namespace std; bool nozero(int no) { int d; while(no!=0) { d=no%10; if(d==0) return false; no/=10; } return true; } void f() { int x,y,z,a; for(int i=0;i<1000;i++) { x=1+(rand()%98); if(nozero(x)) break; else continue; } a=100-x; for(int i=0;i<1000;i++) { for(int j=0;j<100;j++) { y=rand(); if(nozero(y)) break; else continue; } for(int k=0;k<100;k++) { z=rand(); if(nozero(z)) break; else continue; } if((y/z==a&&y%z==0)) break; else continue; } cout<<x<<"+"<<y<<"/"<<z<<endl; } int main(void) { srand(time(0)); for(int i=0;i<5;i++) f(); } But on running, it on my PC, I encounter the following problem, that it sometimes stop working, and prints only few of the correct answers. (Sometimes all, sometimes none.) So, how to repair the program? I guess I should make the program save the results in a file, so that whenever it works, the correct ones are saved. This will help me get many results // Atleast after 10-15 runs... Edit : Now, even the answers are coming wrong. Why?