User:Deryck Chan/Cpp

From Wikipedia, the free encyclopedia

Hoi Hao Jung[edit]

#include <cstdlib>
#include <iostream>
#include <time.h>

using namespace std;

int main()
{
    srandom ( time(NULL) );
    int m=(random()%99)+1; // rand%99 gives 0-98, +1 gives 1-99
    int up=100, down=1, n=m;
    for (;;){
        cout << down << " to " << up << endl;
        int in;
        cin >> in;
        if (in==n)
        {
                  cout << "BREAK!" << endl;
                  system ("Pause"); // (Windows, not Unix)
                  break;
        }
        else if (in>up || in<down){}
        else if (in<n)
        {
             down=in;
        }
        else if (in>n)
        {
             up=in;
        }    
    }    
    return 0;
}