0

I've read other questions about this error but non helped. I've tried everything people suggest but i can't get rid of this error: "invalid conversion from 'const char*' to 'char'". This is a simple program to encrypt a given char using Caesar's encryption method.

#include <iostream>
using namespace std;
char encryptChar(char c, int key) {
   int final;
   if (int(c) > 90){
      final = (int(c) + key - 97)%26 + 97;
   }
   else {
      final = (int(c) + key - 65)%26 + 65;
   }
   cout << char(final);
   return char(final);
}
int main(){
   char test = "B";
   encryptChar(test,2);
   return 0;
}
  • 3
    `char test = "B";` isn't correct. `"B"` is a null-terminated *string* not a single character. – Some programmer dude Apr 14 '20 at 09:42
  • Also, what line causes the error? Should say in error message – Ender_The_Xenocide Apr 14 '20 at 09:43
  • I also recommend you learn about the standard character [classification](https://en.cppreference.com/w/c/string/byte#Character_classification) and [manipulation](https://en.cppreference.com/w/c/string/byte#Character_manipulation) functions. – Some programmer dude Apr 14 '20 at 09:43
  • 3
    Avoid magic numbers such as 65, 97. Better to use 'A', 'a' which is more readable/portable. – Jarod42 Apr 14 '20 at 09:45
  • And unfortunately ranges a-z/ A-Z are not guarantied to be contiguous in C++ ([EBCDIC](https://en.wikipedia.org/wiki/EBCDIC) is a counter example). – Jarod42 Apr 14 '20 at 09:47

0 Answers0