Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- void calc_average() {
- int b;
- cout << "Ввоедите оценки для вычисления вседнего\n";
- cout << "Для окончания введите 0\n";
- int sum = 0, n = 0;
- //b = 1;
- cin >> b;
- while (b > 0 && b <= 5) {
- sum += b;
- n++;
- cin >> b;
- }
- cout << "Средний балл: "
- << (double)sum/n
- << endl;
- }
- double power(double x, int n) {
- /*double x = ;
- int n = ;*/
- /*
- if (n == 0)
- return 1;
- */
- double y = 1;
- while (n < 0) {
- y /= x;
- n++;
- }
- while (n > 0) {
- y *= x;
- n--;
- }
- //return pow(x, n);
- return y;
- }
- double power2(double x, int n) {
- double y = 1;
- if (n < 0) {
- n = -n;
- x = 1 / x; // x = x / 2 --> x /= 2
- }
- while (n > 0) {
- y *= x;
- n--;
- }
- //return pow(x, n);
- return y;
- }
- void table_mult() {
- cout << "x\\y\t";
- int x = 2, y = 1;
- while (y < 10) {
- while (x < 10) {
- cout << x * y << '\t';
- x++;
- }
- x = 1;
- cout << endl;
- y++;
- }
- }
- int get_rand(int a, int b) {
- return rand() % (b - a + 1) + a;
- }
- int one_humanstep(int n) {
- int number;
- switch (n)
- {
- case 1: cout << "Первая"; break;
- case 2: cout << "Вторая"; break;
- case 3: cout << "Третья"; break;
- default: cout << n << "-ая"; break;
- }
- cout << " попытка. Введите число :";
- cin >> number;
- return number;
- }
- void run_game() {
- /*
- "УГАДАЙ ЧИСЛО"
- Ваша задача угадать число за
- наименьшее число попыток. Если
- Вы сдаётесь нажмите 0.
- Начнём игру? 1 - да, 0 - нет.
- 1
- Я загадал число от 0 до 500. Угадывай.
- Первая попытка. Введите число: 250.
- 250 больше числа, которое я загадал.
- Вторая попытка. Введите число: 120.
- 120 меньше числа, которое я загадал.
- Третья попытка. Введите число: 134.
- Поздравляю, Вы угадали.
- */
- cout << " \"УГАДАЙ ЧИСЛО\" " << endl;
- cout << R"(
- Ваша задача угадать число за
- наименьшее число попыток.
- Если Вы сдаётесь нажмите 0.
- )" << endl;
- cout << "Начнём игру? 1 - да, 0 - нет." << endl;
- int is_start, ai_number, number;
- int step = 0;
- cin >> is_start;
- if (is_start) {
- cout << "Я загадал число от 0 до 500. Угадывай." << endl;
- ai_number = get_rand(1, 500);
- ai_number = 55;
- while (true) {
- step++;
- number = one_humanstep(step);
- if (number <= 0 || number == ai_number) {
- break;
- }
- }
- if (number == ai_number) {
- cout << "Выйграли" << endl;
- }
- else {
- cout << "Проиграли" << endl;
- }
- //cout << ai_number << endl;
- /*
- cout << "Первая попытка.Введите число :";
- cin >> number;
- if (number != 0) {
- if (number != ai_number) {
- cout << number << "больше числа, которое я загадал." << endl;
- cout << "Вторая попытка.Введите число :";
- cin >> number;
- if (number != 0) {
- if (number != ai_number) {
- }
- }
- */
- }
- }
- void test_random() {
- cout << "time: " << time(NULL) << endl << endl;
- int n = 0;
- while (n < 50) {
- //int x = rand() % 500 + 1; /// [0, 499] --> [1, 500]
- int x = get_rand(-5, 5);
- cout << x << endl;
- n++;
- }
- }
- int main() {
- setlocale(LC_ALL, "ru");
- srand(time(NULL));
- /*one_humanstep(1);
- one_humanstep(2);
- one_humanstep(3);
- one_humanstep(400);
- */
- //table_mult();
- //calc_average();
- //cout << power(2, -4) << endl;
- /*cout << 2 * power(val, 4) << endl;
- double y = power(3.0, 4) * sin(0.1);
- cout << y << endl;*/
- //test_random();
- run_game();
- }
Advertisement
Add Comment
Please, Sign In to add comment