Hello. I am trying to figure out why my program has an infinite loop :/ The program asks a user how many digits they want their numbers to be and then the program needs to print out all binary numbers for the user inputted digits.
For example: User inputs 3
Program needs to output:
000
001
010
011
100
101
111
On paper when I work it out my calc functions work, but it does not when I run it. I appreciate the help. Thank you.
{
if(b[index] == 0)
b[index] = 1;
else
{
b[index] = 0;
index -= 1;
calc(b,index);
}
}
int main()
{
string input; // Holds the A-Z values
vector<int> intVec;
int *bin, // Array of binary values (0 and 1's)
index,
choice,
sz = 0, // Size used for in graph size
i; // Used in loops
cout << "Please enter in the number of digits" << endl;
cin >> input;
choice = atoi(input.c_str());
bin = new int[choice];
for(i=0; i < choice; i++)
intVec.push_back(0);
sz = pow(2,choice);
sz -= 1;
index = choice - 1;
for(i=0;i<intVec.size(); i++)
cout << intVec[i];
cout << " " << endl;
cout << sz << endl;
for(i=0; i < sz; i++)
{
index = 2;
calc(intVec, index);
for(i=0;i<intVec.size(); i++)
cout << intVec[i];
cout << " " << endl;
}
intVec.clear();
exit(0);
for(i=0; i < choice; i++)
intVec.push_back(1);
for(i=0;i<intVec.size(); i++)
cout << intVec[i];
return 0;
}