I'm not sure if I did this properly. The program works fine but I don think that is what the problem is asking for.
Any other ways to accomplish this task?
Thanks in advance!
Here's the problem
Code:
Name and load two parallel arrays for the following table. Write a search routine (not a whole program)
that uses the input variable deptName to extract the access code.
Department Access Code
Accounting 1123X5
Receiving 1154V2
Sales 8823Q1
Management 5412R7
and my solution:
Code:
#include<iostream.h>
int main()
{
char department[4][15] = {"Accounting", "Receiving", "Sales", "Management"};
char access_code [4][15] = {"1123X5", "1154V2", "8823Q1", "5412R7",};
cout << "\n Please enter department number to retreive the access code:";
cout << "\n Accounting = 1";
cout << "\n Receiving = 2";
cout << "\n Sales = 3";
cout << "\n Management = 4" << endl;
int deptName;
cin >> deptName;
cout << department[deptName-1] << " ";
cout << "\nAccess code is: " << access_code[deptName-1] << endl;
return 0;
}