// Aufgabe 22.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include "std-rene-schwarz.h"
#include "math.h"


int _tmain(int argc, _TCHAR* argv[])
{
	cout << rsheader << endl;
	cout << "Aufgabe 22\nErraten einer nat. Zahl - Bisektionsverfahren\n\n\n" << endl;

	int a, b, x, i, i2 = 0;

	cout << "Bitte geben Sie ein offenes Intervall an.\nlinke Intervallgrenze a: ";
	cin >> a;
	cout << "rechte Intervallgrenze b: ";
	cin >> b;
	if( a > b )
	{
		i = a;
		a = b;
		b = i;
		i = 0;
	}
	cout << "Nun denken Sie sich bitte eine natürliche Zahl innerhalb des Intervalls ]" << a << ";" << b << "[ !" << endl;
	cout << "Folgende Eingabeoptionen stehen Ihnen zur Verfügung:" << endl;
	cout << "1: ja         2: nein       3: Zahl erraten\n" << endl;

	do
	{
		x = (a+b)/2;
		i2++;
		cout << "Ist die gedachte Zahl größer als " << x << " (Taste 3 falls die Zahl erraten ist)? ";
		cin >> i;
		switch(i)
		{
			1:
				a = x;
				break;
	
			2:
				b = x;
				break;

			3:
				break;

			default:
				cout << "Die gewählte Taste ist nicht belegt. Bitte neu eingeben: ";
				cin >> i;
				break;
		}
	}
	while(i != 3);
	
	cout << "\nDie gedachte Zahl war " << x << " und wurde mit " << i2 << " Fragen erraten." << endl;

	system("PAUSE");
	return 0;
}
