Hello,
I'm studding c++ by S. Prata book.
And there is such exercise
"When you join the Benevolent Order of Programmers,you can be known at BOP
meetings by your real name,your job title,or your secret BOP name.Write a pro-
gram that can list members by real name,by job title,by secret name,or by a mem-
ber’s preference."
I have wrote the code but it doesn't work properly.
When I'm entering a, b or c in the switch the for loop shows
only one of the value,
the for loops doesn't go through of array
What I did wrong?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
|
#include <iostream>
#include <string>
const int MAX = 3;
using namespace std;
struct bop
{
string fullName; //real name
string title; //job title
string bopName; //secret BOP name
int preference; //0 = fullname,
};
int main()
{
cout << "BOP report" << endl
<< "a) display by name \t" << "b) display by title" << endl
<< "c) display by bopname \t" << "d) display by preference " << endl
<< "q) quit" << endl;
bop name[MAX]{"Nyk", "Bob", "Jon" }; // name array
bop tit[MAX]{ "Manager", "Programmer", "Worker" }; //title array
bop bopN[MAX]{ "BBB", "NNNN", "KKK" }; //bopname
char ch;
cout << "Enter your choice: ";
cin >> ch;
while(ch!='a'&&ch!='b'&&ch!='c'&&ch!='d'&&ch!='q')
{
cout << "Please enter a, b, c, d or q to escape: ";
cin >> ch;
}
switch (ch)
{
case 'a':
cout << "By name:" << endl;
for(int i=0; i<MAX; i++)
{
cout << name[i].fullName << endl;
}
break;
case 'b':
cout << "By title:";
cout << endl;
for(int j = 0; j<MAX; j++)
{
cout << tit[j].title << endl;
}
break;
case 'c':
cout << "By bopname:" << endl;
for(int k=0; k<MAX; k++)
{
cout << bopN[k].bopName << endl;
}
break;
}
cout << "Done ";
return 0;
}
|