Thread: Program was working good until.....

  1. #1
    Registered User
    Join Date
    Jan 2002
    Posts
    15

    Unhappy Program was working good until.....

    /*
    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

  2. #2
    ¡Amo fútbol!
    Join Date
    Dec 2001
    Posts
    2,138
    cin >> searchkey[da]; // R&B


    How can this be done if searchkey is an int and not an array??


    Fix that and then come back.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 10
    Last Post: 09-07-2008, 11:38 PM
  2. Program not working right
    By blindman858 in forum C++ Programming
    Replies: 3
    Last Post: 04-17-2005, 09:37 AM
  3. Program not working
    By jat421 in forum C Programming
    Replies: 6
    Last Post: 03-20-2005, 08:28 PM
  4. fopen();
    By GanglyLamb in forum C Programming
    Replies: 8
    Last Post: 11-03-2002, 12:39 PM
  5. Program logic not working..
    By ronkane in forum C++ Programming
    Replies: 2
    Last Post: 01-22-2002, 08:31 PM