Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

NASA has decided to go back and use modems to communicate between computers (the

ID: 3778295 • Letter: N

Question

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

Explanation / Answer

#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<<" Welcome to the NASA's modem number generator"<<endl
           <<" You will enter the first four digits of the phone number, "<<endl
           <<" and then be given options for the last six numbers. "<<endl
           <<" Enter the first four desired numbers: ";
          
      //while statement to input numbers to array
       for(int i = 0; i < 4; i++)
       {
           cout<<" ";
           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;
}