I'm working on a C++ project and have run into an issue that is leaving me puzzled. I am to create a phone number generator that has the user enter the first 4 numbers, and then generate all possible phone numbers that follow these two rules: The last 6 digits must equal 33. The 4th and 5th digit cannot both be even or both be odd.
This is what I've come up with so far:
#include <iostream>
using namespace std;
int main()
{//begin main
srand(time(0));
const int MAX_DIGITS = 10;
int num[MAX_DIGITS] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
cout<<"enter the first digit: ";
cin>>num[0];
cout<<"Enter the second digit: ";
cin>>num[1];
cout<<"Enter the third digit: ";
cin>>num[2];
cout<<"Enter the fourth digit: ";
cin>>num[3];
for (int e=0;e<MAX_DIGITS;e++)
{
for(int f=0;f<MAX_DIGITS;f++)
{
for(int g=0;g<MAX_DIGITS;g++)
{
for(int h=0;h<MAX_DIGITS;h++)
{
for(int i=0; i<MAX_DIGITS;i++)
{
for(int j=0;j<MAX_DIGITS;j++)
{
if ((num[e]+num[f]+num[g]+num[h]+num[i]+num[j]) == 33 && (num[3]%2 != 0 && num[4]%2 != 0) )
{
cout<<num[0]<<num[1]<<num[2]<<num[3]<<num[e]<<num[f]<<num[g]<<num[h]<<num[i]<<num[j]<<endl;
}
}
}
}
}
}
}
It all makes sense to me so far, but the program is displaying some numbers multiple times, and I'm not entirely certain how to make sense of the even/odd rule.
I'm still a rookie to programming and I'm sure that there may be a more efficient way to do this, but I'm trying my best and this has left me puzzled. Any help would be appreciated.
Thanks in advance!
EDIT: My question is this, how do I get the generator to display the numbers with the even/odd rule applied? My best idea was to use the modulus operator (%) to see if the remainder of the numbers divided by two was zero, and if so, the numbers were even. This is where I stumble a bit though, because I'm not perfectly certain how to implement this. Sorry for not being more specific the first time.