Language: C++

#include <iostream>
#include <cstdlib>

int get_three_num(string str, int index);
int calc_sub(int num);

int main(void)
{
  string str;
  int closest_num;
  int current_num;
  
  cin >> str;
  
  closest_num = get_three_num(str, 0);
  for(int i = 1; i < str.length() - 2; i++){
    current_num = get_three_num(str, i);
    
    if(calc_sub(closest_num) > calc_sub(current_num)){
      closest_num = current_num;
    }
  }
  
  cout << closest_num;
  
  return 0;
}

int get_three_num(string str, int index)
{
  int num;
  
  for(i = index; i < index + 3; i++){
    num += pow(10, 2 - (i - index));
  }
  
  return num;
}

int calc_sub(int num)
{
  return abs(753 - num);
}


Compiler output:
a.cc:4:19: error: 'string' was not declared in this scope
    4 | int get_three_num(string str, int index);
      |                   ^~~~~~
a.cc:4:19: note: suggested alternatives:
In file included from /usr/include/c++/14/iosfwd:41,
                 from /usr/include/c++/14/ios:40,
                 from /usr/include/c++/14/ostream:40,
                 from /usr/include/c++/14/iostream:41,
                 from a.cc:1:
/usr/include/c++/14/bits/stringfwd.h:77:33: note:   'std::string'
   77 |   typedef basic_string<char>    string;
      |                                 ^~~~~~
In file included from /usr/include/c++/14/bits/locale_classes.h:40,
                 from /usr/include/c++/14/bits/ios_base.h:41,
                 from /usr/include/c++/14/ios:44:
/usr/include/c++/14/string:76:11: note:   'std::pmr::string'
   76 |     using string    = basic_string<char>;
      |           ^~~~~~
a.cc:4:31: error: expected primary-expression before 'int'
    4 | int get_three_num(string str, int index);
      |                               ^~~
a.cc:4:40: error: expression list treated as compound expression in initializer [-fpermissive]
    4 | int get_three_num(string str, int index);
      |                                        ^
a.cc: In function 'int main()':
a.cc:9:3: error: 'string' was not declared in this scope
    9 |   string str;
      |   ^~~~~~
a.cc:9:3: note: suggested alternatives:
/usr/include/c++/14/bits/stringfwd.h:77:33: note:   'std::string'
   77 |   typedef basic_string<char>    string;
      |                                 ^~~~~~
/usr/include/c++/14/string:76:11: note:   'std::pmr::string'
   76 |     using string    = basic_string<char>;
      |           ^~~~~~
a.cc:13:3: error: 'cin' was not declared in this scope; did you mean 'std::cin'?
   13 |   cin >> str;
      |   ^~~
      |   std::cin
/usr/include/c++/14/iostream:62:18: note: 'std::cin' declared here
   62 |   extern istream cin;           ///< Linked to standard input
      |                  ^~~
a.cc:13:10: error: 'str' was not declared in this scope; did you mean 'std'?
   13 |   cin >> str;
      |          ^~~
      |          std
a.cc:15:30: error: 'get_three_num' cannot be used as a function
   15 |   closest_num = get_three_num(str, 0);
      |                 ~~~~~~~~~~~~~^~~~~~~~
a.cc:17:32: error: 'get_three_num' cannot be used as a function
   17 |     current_num = get_three_num(str, i);
      |                   ~~~~~~~~~~~~~^~~~~~~~
a.cc:24:3: error: 'cout' was not declared in this scope; did you mean 'std::cout'?
   24 |   cout << closest_num;
      |   ^~~~
      |   std::cout
/usr/include/c++/14/iostream:63:18: note: 'std::cout' declared here
   63 |   extern ostream cout;          ///< Linked to standard output
      |                  ^~~~
a.cc: At global scope:
a.cc:29:5: error: redefinition of 'int get_three_num'
   29 | int get_three_num(string str, int index)
      |     ^~~~~~~~~~~~~
a.cc:4:5: note: 'int get_three_num' previously defined here
    4 | int get_three_num(string str, int index);
      |     ^~~~~~~~~~~~~
a.cc:29:19: error: 'string' was not declared in this scope
   29 | int get_three_num(string str, int index)
      |                   ^~~~~~
a.cc:29:19: note: suggested alternatives:
/usr/include/c++/14/bits/stringfwd.h:77:33: note:   'std::string'
   77 |   typedef basic_string<char>    string;
      |                                 ^~~~~~
/usr/include/c++/14/string:76:11: note:   'std::pmr::string'
   76 |     using string    = basic_string<char>;
      |           ^~~~~~
a.cc:29:31: error: expected primary-expression before 'int'
   29 | int get_three_num(string str, int index)
      |                               ^~~