Question: Please check my C++ code, I need this program to loop through and check all possible combinations until the code that comes out is 872159;

Please check my C++ code, I need this program to loop through and check all possible combinations until the code that comes out is 872159;

/*

*/

#include #include #include

using namespace std;

string lockerCombo = "000009"; string twoOneCheck;

bool lockerComboValid();

bool lockerComboValid(){ for (int i = 0; i < lockerCombo.length(); i++) { for(int j = 0; j < lockerCombo.length(); j++) { if(lockerCombo[i] != lockerCombo[j]) { return true; } else { return false; } } } }

int main() { // do{ for(int k = 0; k < 9; k++) { to_string(k); lockerCombo[1] = 48 + k; for(int i = 0; i < 9; i++) { to_string(i); lockerCombo[3] = 48 + i; if ((int)lockerCombo[1] - (int)lockerCombo[3] == 6) { break; } } } for(int o = 0; o < 9; o++) { to_string(o); lockerCombo[0] = 48 + o; for(int p = 0; p < 9; p++) { to_string(p); lockerCombo[4] = 48 + p; if (((int)lockerCombo[0] - 48) + ((int)lockerCombo[1] - 48)/3 == ((int)lockerCombo[4] - 48)); { break; } } }

//}while(lockerComboValid() == false); cout << "The Combo is - " << lockerCombo; return 0; }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!