NASA has decided to go back and use modems to communicate be
NASA has decided to go back and use modems to communicate between computers (they must have missed the War Games video). 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.
Write a phone number generator that asks for the first four digits. The computer must generate a list of all possible phone numbers that meet the new security rule, and display them as follows:
(XXX) - XXX - XXXX
Solution
#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
int main()
{
int i = 0;
char playAgain;
do
{
srand (static_cast<unsigned int>(time(0)));
int firstFour[5];
int lastSix[7];
cout<<\"\ \ \\t\\tWelcome to the NASA\'s modem number generator\"<<endl
<<\"\\t\\tYou will enter the first four digits of the phone number, \"<<endl
<<\"\\t\\tand then be given options for the last six numbers. \"<<endl
<<\"\ \\t\\tEnter the first four desired numbers: \";
//while statement to input numbers to array
for(int i = 0; i < 4; i++)
{
cout<<\"\ \\t\\t\";
cout<<i + 1<<\". \";
cin>>firstFour[i];
}
//do loop to check if == to 33
int j=0;
do
{
int i = 0;
//check if 4th number is even
if(firstFour[3] % 2 == 0)
{
do
{
lastSix[0] = rand() % 9;
}while(lastSix[0] % 2 == 0);
for(int i = 1; i < 6; i++)
{
lastSix[i] = rand() % 10;
}
}else
if(firstFour[3] % 2 != 0)
{
do
{
lastSix[0] = rand() % 10;
}while(lastSix[0] % 2 != 0);
}
for(int i = 1; i < 6; i++)
{
lastSix[i] = rand()% 10;
}
int sum = 0;
for (int i=0; i<6; i++)
{
sum+= lastSix[i];
}
if(sum == 33)
{
//display chosen number
cout<<\"(\";
for(int i = 0; i < 3; i++)
{
cout<<firstFour[i];
}
cout<<\")-\"<<firstFour[3]<<lastSix[0]<<lastSix[1]<<\"-\";
for(int i = 2; i< 6; i++)
{
cout<<lastSix[i];
}
cout<<\"\ \";
}
j++;
}while(j < 500);
cout<<\"Run again?\";
cin>> playAgain;
}while (playAgain == \'y\');
system(\"pause\");
return 0;
}

