### Homework help

I am trying to get the last 6 digits to go through a recursion and display only when those variables add up to a specific #.

The code runs, but just gives me the first recursion. Any advice would be appreciated.

 ``1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465`` ``````#include "stdafx.h" #include #include #include #include //for srand and rand using namespace std; int _tmain(int argc, _TCHAR* argv[]) { int a,b,c,d,e,f,g,h,i,j; cout << "Welcome to create that phone number" << endl; cout << "Please enter a number 1-9 that is the first number" << endl; cin >> a; cout << "Please enter a number 1-9 that is the second number" << endl; cin >> b; cout << "Please enter a number 1-9 that is the third number" << endl; cin >> c; cout << "Please enter a number 1-9 that is the fourth number" << endl; cin >> d; if (d %2 != 0) { e = 0; } else { e = 1; } do { for (e = 1; e < 10; e++); { for (f = 1; e < 10; e++); { for (g = 1; e < 10; e++); { for (h = 1; e < 10; e++); { for (i = 1; e < 10; e++); { for (j = 1; e < 10; e++); } } } } } } while ('e' + 'f' + 'g' + 'h' + 'i'+ 'j' == 33); { cout << "Phone number is" << a << b << c << d << e << f << g << h << i << j << endl; } system("pause"); return 0; }``````
How exactly did you plan to get this thing to create a recursion? I don't see anything being done in the for-loops and there is not recursion going on here, just a lot of for-loops. Why are the numbers on line 56 in single quotes? After your last for-loop runs, everything stops because e will be 10 since that is your condition for the other loops. Line 56 also will most likely not run because since you only incremented e to 10, if the other numbers plus e is not equal to 33, it stops.

You have to rethink your algorithm because it is very flawed at this point
Last edited on
Fixed it up a bit, don't know why it's screwing up

 ``1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374`` ``````#include #include #include //for srand and rand using namespace std; int main(int nNumberofArgs,char* pszArgs[]) { int a,b,c,d,e,f,g,h,i,j = 0; cout << "Welcome to create that phone number" << endl; cout << "Please enter a number 1-9 that is the first number" << endl; cin >> a; cout << "Please enter a number 1-9 that is the second number" << endl; cin >> b; cout << "Please enter a number 1-9 that is the third number" << endl; cin >> c; cout << "Please enter a number 1-9 that is the fourth number" << endl; cin >> d; for(int n = 0;n < 60;n++) { for (e = 0; e < 9; e++); { if(e + f + g + h + i + j == 33) { cout << "Phone number is " << a << b << c << "-" << d << e << f << "-" << g << h << i << j << endl; } for (f = 0; f < 9; f++); { if(e + f + g + h + i + j == 33) { cout << "Phone number is " << a << b << c << "-" << d << e << f << "-" << g << h << i << j << endl; } for (g = 0; g < 9; g++); { if(e + f + g + h + i + j == 33) { cout << "Phone number is " << a << b << c << "-" << d << e << f << "-" << g << h << i << j << endl; } for (h = 0; h < 9; h++); { if(e + f + g + h + i + j == 33) { cout << "Phone number is " << a << b << c << "-" << d << e << f << "-" << g << h << i << j << endl; } for (i = 0; i < 9; i++); { if(e + f + g + h + i + j == 33) { cout << "Phone number is " << a << b << c << "-" << d << e << f << "-" << g << h << i << j << endl; } for (j = 0; j < 9; j++); { if(e + f + g + h + i + j == 33) { cout << "Phone number is " << a << b << c << "-" << d << e << f << "-" << g << h << i << j << endl; } } } } } } } } system("PAUSE"); return 0; } ``````
Topic archived. No new replies allowed.