Книги
- 1 ответ
- 0 вопросов
11
Вклад в тег
This rule means that if the header uses a type - such as 'FILE *' or 'size_t' - then it must ensure that the appropriate other header ( or for example) should be included. A corollary, often forgotten, is that the header should not include any other header that is not needed by the user of the package in order to use the package. The header should be minimal, in other words.
#include <iostream>
#include <cmath>
using namespace std;
int main()
{
setlocale(LC_ALL, "Russian");
int min = 1, max = 100;
cout << "Загадайте число от " << min << " до " << max << ".\n";
int guess = (min + max) / 2, count = (int) ceil(std::log2(max - min));
for (int i = 0; i < count; ++i)
{
cout << "Загаданное число меньше или равно " << guess << "? (y/n)\n"; // fixed
char ans;
cin >> ans;
if (ans == 'y')
{
max = guess;
}
else
{
min = guess + 1; // fixed
}
guess = (min + max) / 2;
if (max == min) // fixed
{
cout << "Вы загадали число \"" << guess << "\".\n";
system("PAUSE");
return 0;
}
}
cout << "Жулик!\n";
system("PAUSE");
return 0;
}