View Single Post
 
[C++]Guess you number
Reply
Posted 2004-01-30, 04:44 PM
This is a program I helped a new C++ programmer with... I figured someone might want it here


Code:
#include <windows.h>
#include <iostream.h>

int main(int argc, char* argv[])
{
	char z = (int)65;
	cout<<z;
	int number;
	cout<<"Pick a number 1-100 ";
	cin>>number;

	int guess = 50,last_guess = guess, input = 0;
    int high = 100, low = 1;

	while(guess != number){
        cout<<"Is your number "<<guess<<"? [1]yes [2]no ";
		cin>>input;
		if(input == 1)
			break;
		else {
            cout<<"Is it [1]higher or [2]lower? ";
			cin>>(int)input;
			if(input == 1){
               guess = (int)((last_guess + high) /2);
			   low = last_guess;
			}
			else if(input == 2) {
               guess = (int)((last_guess + low) /2);
			   high = last_guess;
			}

		}
		last_guess = guess;
	}
	cout<<"So you number is "<<guess<<endl;
	return 0;
}
Old
Profile PM WWW Search
Acer enjoys the static noises of ten television sets simultaneously tuned to 412.84 MHzAcer enjoys the static noises of ten television sets simultaneously tuned to 412.84 MHz
 
 
Acer