fork download
  1. #if defined(_WIN32) // количество цифр в INT_MAX
  2. #define MAX_TYPE 10
  3. #elif defined(_WIN64)
  4. #define MAX_TYPE 19
  5. #endif
  6. double Racially_Correct_Input(char a[]) //функция для ввода допустимых значений с клавиатуры
  7. {
  8. double c, num, z;
  9. int i = 0;
  10. int flagpoint = 0; //признак того, что точка есть в числе
  11. char str[MAX_TYPE + 2];//строка с числом
  12. while ((c = getch()) != 13 || i == 0) //ввод числа до нажатия enter
  13. {
  14. if (i > MAX_TYPE ) //проверка на домустимый размер числа (проверка при помощи INT_MAX есть на выходе)
  15. {
  16. for (i; i > 1; str[i--])//очистка экрана от введённого числа
  17. {
  18. printf("\b \b");
  19. }
  20. printf("\b \b");
  21. printf("Nedopustimii razmer!");
  22. getch();
  23. for (int j = 0; j < 20; j++) //очистка консоли от printf("Nedopustimii razmer!");
  24. {
  25. printf("\b \b");
  26. }
  27. if (a == "int") return Racially_Correct_Input("int");// если нужно НАТУРАЛЬНОЕ число
  28. if (a == "double") return Racially_Correct_Input("double");//всё остальное
  29. }
  30. if (isdigit(c) || (c == '-') && (i == 0) && a == "double" || a == "double" && (c == '.') && !flagpoint) //Если символ является цифрой или знаком /* || c == '.'*/)
  31.  
  32. {
  33. if (c == '.') { flagpoint = 1; z = i; } //Если ввели точку, меняем флаг, обозначающий, что точка введена
  34.  
  35. str[i++] = (char)c;
  36. putch(c);
  37. }
  38. else if (c == 8 && i > 0) // 8 - keys BACKSPACE
  39. {
  40. printf("\b \b"); // destructive backspace
  41. if (i - 1 == z) flagpoint = 0;
  42. str[i--] = (char)c;
  43. }
  44. else if (c == 27) //выход из программы и очистка памяти при помощи самопальной функции
  45. {
  46. Free(A);
  47. exit(1);
  48. }
  49. else if (c == 32 ) //рестарт программы
  50. {
  51. Free(A);
  52. menu();
  53. }
  54. }
  55. str[i] = '\0'; //Сформированную строку заершаем признаком окончания строки
  56.  
  57. num = atof(str); //Преобразуем строку в число с точкой
  58. if (atof(str) > INT_MAX)
  59. {
  60. printf("\nNedopustimii razmer!\n");
  61. if (a == "int") return Racially_Correct_Input("int");
  62. if (a == "double") return Racially_Correct_Input("double");
  63. }
  64. return num;
  65. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp: In function 'double Racially_Correct_Input(char*)':
prog.cpp:11:11: error: 'MAX_TYPE' was not declared in this scope
  char str[MAX_TYPE + 2];//строка с числом
           ^
prog.cpp:12:20: error: 'getch' was not declared in this scope
  while ((c = getch()) != 13 || i == 0) //ввод числа до нажатия enter
                    ^
prog.cpp:16:19: error: 'str' was not declared in this scope
    for (i; i > 1; str[i--])//очистка экрана от введённого числа
                   ^
prog.cpp:18:19: error: 'printf' was not declared in this scope
     printf("\b \b");
                   ^
prog.cpp:20:18: error: 'printf' was not declared in this scope
    printf("\b \b");
                  ^
prog.cpp:27:55: warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]
    if (a == "int") return Racially_Correct_Input("int");// если нужно НАТУРАЛЬНОЕ число
                                                       ^
prog.cpp:28:61: warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]
    if (a == "double") return Racially_Correct_Input("double");//всё остальное
                                                             ^
prog.cpp:30:16: error: 'isdigit' was not declared in this scope
   if (isdigit(c) || (c == '-') && (i == 0) && a == "double" || a == "double" && (c == '.') && !flagpoint)  //Если символ является цифрой или знаком  /* || c == '.'*/)
                ^
prog.cpp:35:5: error: 'str' was not declared in this scope
     str[i++] = (char)c;
     ^
prog.cpp:36:12: error: 'putch' was not declared in this scope
     putch(c);
            ^
prog.cpp:40:19: error: 'printf' was not declared in this scope
     printf("\b \b"); // destructive backspace
                   ^
prog.cpp:42:5: error: 'str' was not declared in this scope
     str[i--] = (char)c;
     ^
prog.cpp:46:10: error: 'A' was not declared in this scope
     Free(A);
          ^
prog.cpp:46:11: error: 'Free' was not declared in this scope
     Free(A);
           ^
prog.cpp:47:11: error: 'exit' was not declared in this scope
     exit(1);
           ^
prog.cpp:51:10: error: 'A' was not declared in this scope
     Free(A);
          ^
prog.cpp:51:11: error: 'Free' was not declared in this scope
     Free(A);
           ^
prog.cpp:52:10: error: 'menu' was not declared in this scope
     menu();
          ^
prog.cpp:55:2: error: 'str' was not declared in this scope
  str[i] = '\0'; //Сформированную строку заершаем признаком окончания строки
  ^
prog.cpp:57:16: error: 'atof' was not declared in this scope
  num = atof(str); //Преобразуем строку в число с точкой
                ^
prog.cpp:58:18: error: 'INT_MAX' was not declared in this scope
  if (atof(str) > INT_MAX)
                  ^
prog.cpp:60:36: error: 'printf' was not declared in this scope
   printf("\nNedopustimii razmer!\n");
                                    ^
prog.cpp:61:54: warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]
   if (a == "int") return Racially_Correct_Input("int");
                                                      ^
prog.cpp:62:60: warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]
   if (a == "double") return Racially_Correct_Input("double");
                                                            ^
stdout
Standard output is empty