I wrote the other day the descrambler of the Caesar cipher in C ++. But there was a problem with the encryption id. The compiler writes that it is not defined. Specified prototypes of void Crypt(); functions void Crypt(); and void encrypt(); before use. Did not help. I left the source code of the program below.

The program is written in Visual Studio 2017. Error code E0020 (if required).

 #include "pch.h" #include <iostream> #include <vector> #include <string> using namespace std; int main() { string s; getline(cin, s); vector<int> vec(26); for (auto& c : s) { if (c >= 'a' && c <= 'z') vec[c - 'a']++; else if (c >= 'A' && c <= 'Z') vec[c - 'A']++; } int max_index = 0; for (int i = 1; i < 26; i++) { if (vec[i] > vec[max_index]) max_index = i; } int key = max_index - 4; while (key < 0) key += 26; cout << encryption(s, 26 - key) << endl; } 

What is wrong, I do not know. I tried to compile with this error, but the results are not very good. Decipher Caesar did not work. Who met with such a problem and knows the solutions please write.

  • 2
    Where did you get the encryption() function? For I also do not see her ads in your code. - Mikhail Murugov
  • The encryption () function is listed at the end of the code. cout << encryption (s, 26 - key) << endl; When adding a function that is responsible for this part of the code, an error occurs. - user318029
  • The function must be declared BEFORE its call. If you have tried void encrypt(); add before the main function, then you skipped the parameters (judging by your call, string and int ). - Mikhail Murugov
  • @ MikhailMurugov I indicated this function and repeatedly, the error remains in the same place) - user318029
  • It can not be. Show your corrected version. - Mikhail Murugov

1 answer 1

First of all, I really recommend that you read the basic concepts of the language again.

Secondly, as already told you, you did NOT declare the function encryption() and also did not initialize its prototype in int main() , which the compiler quite reasonably curses.

In order to use this function, declare it before int main () , give it arguments, in your case it is string &s, int *i give this function logic, what it should do and declare the prototype of this function directly in the function int main() , then the compiler will cease to swear on not declared function.

That is what you were trying to convey ...