Help displaying arrays...
I've been working on a program that tells you all the first and second possible digits for a combination lock, if you give it the third digit (using information I found online, but that's not important). It uses a few arrays that hold the possible combinations, then based on the remainder of the third digit divided by 4, it is supposed to display the possibilities. However, it chooses to display only a few entries of my arrays... I need it to display the whole array, preferably with each entry seperated by comas. Here's the code I've got thus far:
// "Master Lock" combination selector
#include <cstdio>
#include <cstdlib>
#include <iostream>
using namespace std;
int x;
int third;
int rem;
int firstDigits = 0;
int secDigits = 0;
int firstRem0 [10] = { 0, 4, 8, 12, 16, 20, 24, 28, 32, 36 };
int firstRem1 [10] = { 1, 5, 9, 13, 17, 21, 25, 29, 33, 37 };
int firstRem2 [10] = { 2, 6, 10, 14, 18, 22, 26, 30, 34, 38 };
int firstRem3 [10] = { 3, 7, 11, 15, 19, 23, 27, 31, 35, 39 };
int secRem0 [10] = { 2, 6, 10, 14, 18, 22, 26, 30, 34, 38 };
int secRem1 [10] = { 3, 7, 11, 15, 19, 23, 27, 31, 35, 39 };
int secRem2 [10] = { 0, 4, 8, 12, 16, 20, 24, 28, 32, 36 };
int secRem3 [10] = { 1, 5, 9, 13, 17, 21, 25, 29, 33, 37 };
int computeRemainder();
int computeCombos();
int display();
int main()
{
cout << "This program works only for combination locks with 40 digits (0-39).\n";
cout << "Please enter the third part of the combination using two digits (i.e. 29, 08):\n";
cin >> third;
computeRemainder();
display();
system("PAUSE > PAUSENOTICES.TXT");
system("DEL PAUSENOTICES.TXT");
}
int computeRemainder()
{
rem = third%4;
}
int computeCombos()
{
}
int display()
{
switch (rem)
{
case 0:
for (x=0; x<10; x++)
{
firstDigits += firstRem0[x];
secDigits += secRem0[x];
}
break;
case 1:
for (x=0; x<10; x++)
{
firstDigits += firstRem1[x];
secDigits += secRem1[x];
}
break;
case 2:
for (x=0; x<10; x++)
{
firstDigits += firstRem2[x];
secDigits += secRem2[x];
}
break;
case 3:
for (x=0; x<10; x++)
{
firstDigits += firstRem3[x];
secDigits += secRem3[x];
}
break;
default:
return 0;
break;
}
cout << firstDigits;
cout << endl;
cout << secDigits;
}
Suggetions, please?
[2735 byte] By [
Omega234] at [2007-11-20 11:46:25]

# 2 Re: Help displaying arrays...
Hmm... I've tried your code (but modified it slightly, since it wasn't exactly what I needed), but it's not working quite right. Here's the newly rewritten display part of my code:
int display()
{
switch (rem)
{
case 0:
for (x=0; x<10; x++)
{
firstDigits += firstRem0[x];
cout << firstDigits;
if (x !=9)
{
cout << ", ";
}
}
cout << endl;
for (x=0; x<10; x++)
{
secDigits += secRem0[x];
cout << secDigits;
if (x != 9)
{
cout << ", ";
}
}
break;
case 1:
for (x=0; x<10; x++)
{
firstDigits += firstRem1[x];
cout << firstDigits;
if (x !=9)
{
cout << ", ";
}
}
cout << endl;
for (x=0; x<10; x++)
{
secDigits += secRem1[x];
cout << secDigits;
if (x != 9)
{
cout << ", ";
}
}
break;
case 2:
for (x=0; x<10; x++)
{
firstDigits += firstRem2[x];
cout << firstDigits;
if (x !=9)
{
cout << ", ";
}
}
cout << endl;
for (x=0; x<10; x++)
{
secDigits += secRem2[x];
cout << secDigits;
if (x != 9)
{
cout << ", ";
}
}
break;
case 3:
for (x=0; x<10; x++)
{
firstDigits += firstRem3[x];
cout << firstDigits;
if (x !=9)
{
cout << ", ";
}
}
cout << endl;
for (x=0; x<10; x++)
{
secDigits += secRem3[x];
cout << secDigits;
if (x != 9)
{
cout << ", ";
}
}
break;
default:
return 0;
break;
}
}
When it runs, though, it doesn't display right. If I give it 22 (which makes rem equal to 2), it gives me this:
2, 8, 18, 32, 50, 72, 98, 128, 162, 200
0, 4, 12, 24, 40, 60, 84, 112, 144, 180
But since the remainder is 2, it ought to give me this:
2, 6, 10, 14, 18, 22, 26, 30, 34, 38
0, 4, 8, 12, 16, 20, 24, 28, 32, 36
What did I do wrong?