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.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#include "stdafx.h"
#include<iostream>
#include<iterator>
#include<vector>
#include<cstdlib> //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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#include <iostream>
#include <cstdio>
#include <cstdlib> //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.