You are using a version without Ads of this website. Please, consider donating:

### Program help needed!

I am working on a program that asks the user to input the first 4 digits of a phone number, the computer generates all possible phone numbers that meet the new security rule: In order to provide security, the last 6 digits of the phone number must add to 33. If the fourth number is odd the fifth number must be even. Likewise, if the fourth number is even the fifth number must be odd. The outcomes must be displayed as follows: (XXX) - XXX - XXXX

Here is what I have so far.

 ``12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182`` ``````#include "stdafx.h" #include #include #include #include #include using namespace std; int main() { vector telNums; //list of numbers given by user vector genNums (5, 0); //list of complete numbers generated by computer int telNumber; int even = 0; int odd = 1; int iRand = 0; srand((unsigned int)time(NULL)); cout << "Please enter the first four digits of the telephone number: " << endl; for( int i=0; i<4; i++){ cout << " Enter number " << i+1 << ": " << endl; cin >> telNumber; telNums.push_back(telNumber); } if( (telNums[3] % 2) != 0){ //If telNums 4 is odd... for( int even=0 ; even < 9; even+=2){ for( int j=0; j<10; j++){ genNums[0]++; for( int k=0; k<9; k++){ genNums[1]++; for( int l=0; l<9; l++){ genNums[2]++; for( int m=0; m<9; m++ ){ genNums[3]++; for( int n=0; n<9; n++ ){ genNums[4]++; if( (even + genNums[0] + genNums[1] + genNums[2] + genNums[3] + genNums[4]) == 33){ cout << "(" << telNums[0] << telNums[1] << telNums[2] << ")" << " " << telNums[3] << even << genNums[0] << " " << genNums[1] << genNums[2] << genNums[3] << genNums[4] << endl; } }//It only outputs one outcome and it doesn't even add up to 33 } } } } } } else{ //if telNums 4 is even... for( int odd=1; odd<10; odd+=2){ for( int j=0; j<10; j++){ genNums[0]++; for( int k=0; k<9; k++){ genNums[1]++; for( int l=0; l<9; l++){ genNums[2]++; for( int m=0; m<9; m++ ){ genNums[3]++; for( int n=0; n<9; n++ ){ genNums[4]++; if( (odd + genNums[0] + genNums[1] + genNums[2] + genNums[3] + genNums[4]) == 33){ cout << "(" << telNums[0] << telNums[1] << telNums[2] << ")" << " " << telNums[3] << even << genNums[0] << " " << genNums[1] << genNums[2] << genNums[3] << genNums[4] << endl; } //It only outputs one outcome and it doesn't even add up to 33 } } } } } } } system("pause"); return 0; }``````
Hi, for `vector<int> genNums (5, 0);`, I think it will be `vector<int> genNums (6, 0);`, since you are generating 6 more numbers.

Here is the program,
 ``1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162`` `````` #include "stdafx.h" #include #include #include #include #include #include using namespace std; int main() { vector telNums; //list of numbers given by user vector genNums (6, 0); //list of complete numbers generated by computer int telNumber; int even = 0;//Not needed int odd = 1; //Not needed int iRand = 0; //Not needed srand((unsigned int)time(NULL)); //Not needed cout << "Please enter the first four digits of the telephone number: " << endl; for( int i=0; i<4; i++) { cout << " Enter number " << i+1 << ": "; cin >> telNumber; telNums.push_back(telNumber); } for(int i = 0; i < 9; i+=2) { if (telNums[3]%2 != 0) genNums.at(0) = i; //if the 4th number is odd else genNums.at(0) = i+1; // if the 4th number is even for(int n2 = 0; n2 < 10; n2++) for(int n3 = 0; n3 < 10; n3++) for(int n4 = 0; n4 < 10; n4++) for(int n5 = 0; n5 < 10; n5++) for(int n6 = 0; n6 < 10; n6++) { genNums.at(1) = n2; genNums.at(2) = n3; genNums.at(3) = n4; genNums.at(4) = n5; genNums.at(5) = n6; if (accumulate(genNums.begin(),genNums.end(), 0) == 33) cout << "Numbers: (" << telNums[0] << telNums[1] << telNums[2] << ")-" << telNums[3] << genNums[0] << genNums[1] << "-" << genNums[2] << genNums[3] << genNums[4] << genNums[5] << endl; } } system("pause"); return 0; }``````

Hope it helps! :)
Last edited on
That does help a lot! I tried with the code changes you made, however it is now giving me every possible numbers instead of just the ones that equal 33
Bump!

I need to get this figured out today, if anyone has suggestions please help!
I got it to work! Thanks
Topic archived. No new replies allowed.

You are using a version without Ads of this website. Please, consider donating: