Loops and conditions, need some direction please

working on some error correction scheme.

my code works when I try to find repeating 3's (2) times. But I need to
be able to find the patterns for any number of times. I am kind of lost on where to go from here. I know I am a little sloppy here, but maybe you can
give me some direction?

thanks a million!!



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
75
76
77
78
79
80
81
82
#include <iostream>
using namespace std;

int analyzePatternDigitJeremyM(int arg);

int main () {
int a = 1333343333;
int b = -1333343333;

	
analyzePatternDigitJeremyM(a);

analyzePatternDigitJeremyM(b);

return 0;
}
int analyzePatternDigitJeremyM(int arg) {
	int tempInteger = arg;
	int modifyArg = arg;
	
	int count = 0;
	int digitPatternNumber;
	int digitPatternCount;
	int patternCount = 0;
	int tempPatternCount = 0;


cout << "please enter the digit to be found in a pattern" << endl;
cin >> digitPatternNumber;
cout << "please enter the amount of digits in the pattern to be found." << endl;
cin >> digitPatternCount;

do {									
	tempInteger = tempInteger / 10;
	count++;
} while (tempInteger != 0);
if(modifyArg < 0) {
	modifyArg = -modifyArg;
}
	
int* dynamicArray = new int[count];

for(int index = count -1 ; index >= 0; index--) {
		dynamicArray[index] = modifyArg % 10;
		modifyArg = modifyArg / 10;
}
for(int index = 0 ; count - 1 >= index; index++) {
	cout << dynamicArray[index];
}
cout << endl;

for(int index = count -1 ; index >= 0; index--) {
	if(dynamicArray[index] == digitPatternNumber) {
		tempPatternCount = digitPatternCount;
			if(dynamicArray[index + 1 - tempPatternCount] == digitPatternNumber) {
				tempPatternCount--;
			
				do {
					if(dynamicArray[index + 1 - tempPatternCount] == digitPatternNumber) {
						tempPatternCount--;
					} else if (dynamicArray[index + 1 - tempPatternCount] != digitPatternNumber) {
						break;
					}
				} while(tempPatternCount > 1);

				if(tempPatternCount == 0) {
					dynamicArray[index + 1- digitPatternCount] = 0;
					patternCount++;
					
				}
			}
	
	}

}
for(int index = 0 ; count - 1 >= index; index++) {
	cout << dynamicArray[index];
}
cout << "\n\nthe number of patterns found are: " << patternCount << endl;

return patternCount;
}
Topic archived. No new replies allowed.