# Josephus problem variant logic troubles

```    #include <iostream>     #include <list>     using namespace std;     int main(){       //M: incrememnt amount       //N: size of list/number of current 'persons'       //playerList<int>: our list, numbered 1 to N       //done: becoems true when current persons is 1             bool done = false;       int N = 0;       int M = 0;       cout <<"Please enter # of 'players': ";       cin >> N;       cout <<"\nPlease enter an incriment value: ";       cin >> M;       //check for default case, if there's only a single 'player'       if(N <= 1){           cout <<" We need more players!";           system("PAUSE");           return 0;       }       //so we have our values, lets create our list to spec       list<int> playerList;       for(int i = 0; i < N; i++){           playerList.push_back(i+1);       }       //iterator       list<int>::iterator itr;       itr = playerList.begin();       int tempCount = 1;       //add offset(M) to the iterator starting at begin(gradually). whatever it lands on is erased.       //continue this , and wrap around if iterator == end       while(done == false){           if(N == 1){             done = true;             cout << "\nWinner: Player" << *itr << endl; //outputs what the iterator is pointing at           }           else{             //okay, so now we start to traverse the list                         //do we wrap?             //and we have tempcount to add to the iterator until we reach m             if(itr == playerList.end()){                 if(tempCount == M){                   //temp = true;                   tempCount = 0;                   N--;                   cout << "\n Player " << *itr << " lost.";                   itr = playerList.erase(itr);                                 }                 else{                   itr = playerList.begin(); //almost the same as itr++                   tempCount++;                 }             }                         else{                 //we didn't wrap, what do we do                 //1: increment the iterator//tempcount                 //2: if tempCount = M, delete whats at the iterator                 //2.1: if we delete, reset tempCount, and decrease N, output result                 //3: soemthing                 if(tempCount == M){                   tempCount = 0;                   N--;                   cout << "\n Player " << *itr << " lost.";                   itr = playerList.erase(itr);                                   }                 else{                   if(itr == playerList.end()){                       itr = playerList.begin(); //almost the same as itr++                       tempCount++;                   }                   else{                       itr++;                       tempCount++;                   }                 }                             }//end inside else           }//end else       }//end while       system("PAUSE");       return 0;     }```