fork download
  1. #include <iostream>
  2. #include <math.h>
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7. const int a = 1;
  8. const int b = 99;
  9. int x, y, z; // x - вводим мы, y и z - генерирует машина (z - то, что пытаемся отгадать)
  10. do {
  11. cout << "Введите число:" << endl;
  12. cin >> x;
  13. } while (x < a || x > b); // это просто проверка на введённое число
  14.  
  15. srand(time(NULL));
  16. y = rand() % (b - a) + a; //генерируем y, где он будет равен остатку от деления на 98 (то есть от 0 до 98), но сдвинутый на 1 (то есть от 1 до 99)
  17. //если нужно изменить диапазон просто меняем объявленные в начале константы
  18. z = rand() % (b - a) + a; //генерируем угадываемое число по тому же принципу
  19. if (abs(x - z) < abs(y - z))
  20. cout << "Поздравляем, вы победили!" << endl;
  21. else
  22. cout << "К сожалению компьютер оказался ближе к ответу" << endl;
  23. cout << "Вы ввели: " << x << endl << "ПК предугадал: " << y << endl << "Искомое число: " << z << endl; //вывод чисел для красоты
  24. return 0;
  25. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp:15:5: error: use of undeclared identifier 'srand'
    srand(time(NULL));
    ^
prog.cpp:16:9: error: use of undeclared identifier 'rand'
    y = rand() % (b - a) + a;   //генерируем y, где он будет равен остатку от деления на 98 (то есть от 0 до 98), но сдвинутый на 1 (то есть от 1 до 99)
        ^
prog.cpp:18:9: error: use of undeclared identifier 'rand'
    z = rand() % (b - a) + a;   //генерируем угадываемое число по тому же принципу
        ^
prog.cpp:19:9: error: use of undeclared identifier 'abs'; did you mean 'fabs'?
    if (abs(x - z) < abs(y - z))
        ^~~
        fabs
/usr/include/i386-linux-gnu/bits/mathcalls.h:181:14: note: 'fabs' declared here
__MATHCALLX (fabs,, (_Mdouble_ __x), (__const__));
             ^
/usr/include/math.h:58:26: note: expanded from macro '__MATHCALLX'
  __MATHDECLX (_Mdouble_,function,suffix, args, attrib)
                         ^
/usr/include/math.h:60:22: note: expanded from macro '__MATHDECLX'
  __MATHDECL_1(type, function,suffix, args) __attribute__ (attrib); \
                     ^
/usr/include/math.h:63:31: note: expanded from macro '__MATHDECL_1'
  extern type __MATH_PRECNAME(function,suffix) args __THROW
                              ^
/usr/include/math.h:66:42: note: expanded from macro '__MATH_PRECNAME'
#define __MATH_PRECNAME(name,r) __CONCAT(name,r)
                                         ^
/usr/include/i386-linux-gnu/sys/cdefs.h:88:23: note: expanded from macro '__CONCAT'
#define __CONCAT(x,y)   x ## y
                        ^
prog.cpp:19:9: warning: using floating point absolute value function 'fabs' when argument is of integer type [-Wabsolute-value]
    if (abs(x - z) < abs(y - z))
        ^
prog.cpp:19:9: note: use function 'std::abs' instead
    if (abs(x - z) < abs(y - z))
        ^~~
        std::abs
prog.cpp:19:9: note: include the header <cstdlib> or explicitly provide a declaration for 'std::abs'
prog.cpp:19:22: error: use of undeclared identifier 'abs'; did you mean 'fabs'?
    if (abs(x - z) < abs(y - z))
                     ^~~
                     fabs
/usr/include/i386-linux-gnu/bits/mathcalls.h:181:14: note: 'fabs' declared here
__MATHCALLX (fabs,, (_Mdouble_ __x), (__const__));
             ^
/usr/include/math.h:58:26: note: expanded from macro '__MATHCALLX'
  __MATHDECLX (_Mdouble_,function,suffix, args, attrib)
                         ^
/usr/include/math.h:60:22: note: expanded from macro '__MATHDECLX'
  __MATHDECL_1(type, function,suffix, args) __attribute__ (attrib); \
                     ^
/usr/include/math.h:63:31: note: expanded from macro '__MATHDECL_1'
  extern type __MATH_PRECNAME(function,suffix) args __THROW
                              ^
/usr/include/math.h:66:42: note: expanded from macro '__MATH_PRECNAME'
#define __MATH_PRECNAME(name,r) __CONCAT(name,r)
                                         ^
/usr/include/i386-linux-gnu/sys/cdefs.h:88:23: note: expanded from macro '__CONCAT'
#define __CONCAT(x,y)   x ## y
                        ^
prog.cpp:19:22: warning: using floating point absolute value function 'fabs' when argument is of integer type [-Wabsolute-value]
    if (abs(x - z) < abs(y - z))
                     ^
prog.cpp:19:22: note: use function 'std::abs' instead
    if (abs(x - z) < abs(y - z))
                     ^~~
                     std::abs
prog.cpp:19:22: note: include the header <cstdlib> or explicitly provide a declaration for 'std::abs'
2 warnings and 5 errors generated.
stdout
Standard output is empty