/*
8:31 PM 2/12/02
OS: Win 2K, Desktop Compiler: MS VC++ 6.0
Program was working good until I addded a few codes for the user to check for another piece of data. TNow it's in a continuous loop.
Can a good soul fix my codes:
Thank you...... . . .
-------Configuration: search_key_test - Win32 Debug--------
Linking...
search_key_test.exe - 0 error(s), 0 warning(s)
previous result without the added codes (y/n):
tested: 2/12/02 7:50 p.m Test is ok at first phase
please enter a key to search for: 33
Data found----Press any key to continue
next phase: ask the user to enter another selection
Second phase, the result:
result with added codes asking user to enter another selection:
please enter a key to search for: 17
Data not found
Another selection? (Y or N): y
Data not found
Another selection? (Y or N): n
Data not found
Another selection? (Y or N): Y
Data found----Data not found
Another selection? (Y or N): N
Data found----Data not found
Another selection? (Y or N):
This is a never ending loop, had to forced-cancel the program.
*/
#include <iostream>
#include <cstring>
#include <ctype.h>
#include <cstdlib>
using namespace std;
//#include
using namespace std;
void main(void)
{
char go;
//int da[20];<--// original taken from the net
// do a cin to enter all the data from 1 to 17
int da[20] = {1, 3, 67, 45, 23, 17, 33, 6, 4, 12, 11, 14, 15, 14, 15, 16,
17, 18, 19, 20}; // RBrb&RbrbRB
int I, i, min, center, max, searchkey = 0;
min=0;
max=19;
// not needed -->searchkey=17;
cout << "please enter a key to search for: "; // R&B
//again:
cin >> searchkey[da]; // R&B
for (I=0; I<=max; i++)
{
again:
da[I]=I;
while (min <=max)
{
center=(min + max)/2;
if (searchkey == da[center])
{
cout<< "Data found----";
// original exit(0);
}
else if (searchkey < da[center])
max = center -1;
cout << "Data not found\n";
//do
//{
cout << " Another selection? (Y or N): ";
cin >> go;
if (toupper(go) == 'y') {
goto again;
//cin >> searchkey[da];
}
//else
//{return 0;}
//not used }while (go!='y' || go!='n');
// not used }while ( (go !='y') || (go == 'Y') );
}// end of for
} // end of first while
} // end of main