Iterations

So my assignment is to find any phone number where the 4th # is even and the 5th is odd and when adding the last 6 digits the sum has to be 27.

I think i've got some of it figured out, but where i declare the 4th digit to be a even integer or starting at 0 and then iterating 2 forward I put the next int variable to be the previous plus 1. That seems to be where the hang up is so I am not sure what I am missing.

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
#include "stdafx.h"
#include<iostream>
#include<iterator>
#include<vector>
#include<cstdlib> //for srand and rand
using namespace std;
int e;  // global variables
int f;  // global variables
int g;  // global variables
int h;  // global variables
int i;  // global variables
int j;  // global variables

int _tmain(int argc, _TCHAR* argv[])
{
	int a,b,c,d;

		

	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 e = 0; e < 10; e+=2);
	for (int f = e+1; f < 10; f +=2);
	for (int g = e; g < 10; ++g);
	for (int h = g; h < 10; ++h);
	for (int i = h; i < 10; ++i);
	for (int j = i; j < 10; ++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;
	
}


Thanks
It isn't clear what you're trying to accomplish with lines 30 to 35. Those are empty for loops that pretty much do nothing. If those variables lived beyond the for loops it would be equivalent to:

1
2
3
4
5
6
int e = 10;
int f = 11 ;
int g = 10 ;
int h = 10 ;
int i = 10 ;
int j = 10 ;


If I were you I would enter the phone numbers as strings. That would make it fairly easy to manipulate or check individual digits.
I don't understand.
Topic archived. No new replies allowed.