I'm experimenting while learning about these loops, and when i nest them i can get results, but not intended results where i want them.
The intended output would look like:
But is returning n.69 - # (where # is an infinite loop)
There's two problems present:
1) n.### should be a 3 digit number
2) - (hits) should return a number <= 100 (i seriously doubt the same letter would be in this message more than 30 times
Here's the code for the loop:
1 2 3 4 5 6 7 8 9
|
for (b=0; b<1098;) {
if (b%3 == 0 || b == 0) {
for (f=0; f<1098;) {
if (tempSum == tempArr) { hits++; } // HERE is where the results are skewed
else { f++; }
cout << "N." << tempSum << " - " << hits << endl;
}
else { b++; }
}/*END LOOP*/
|
And here is tempSum, please note that this is a storage value for the return of the function sum() and equally for tempArr there is a storage vallue for sum2()
1 2 3 4 5 6 7
|
short sum () {
q=b;
x = message[q];
y = message[q+1];
z = message[q+2];
return ((x+y+z) - offset);
}
|
Should i find a new way to sort the array? (Array holds 1098 ints, every 3 ints is equal to a set of numbers i will need later.) ;; While learning i've heard about more advanced ways to sort arrays (vectors / maps) but i'm actually curious of WHY this doesnt work, moreso than what would work, even though i do appreciate hints to what would work.