a value of type "const char *" cannot be assigned to an entity of type "char" C OOP
c++, oop
Solution
C++ has two types of constants consisting of characters - string literals and character literals.
- String literals are enclosed in double quotes, and have type of `const char *`
- Character literals are enclosed in single quotes, and have type `char`.
String literals allow multiple characters; character literals allow only one character. The two types of literals are not compatible: you need to supply a variable or a constant of a compatible type for the left side of the assignment. Since you declared `grade` as a `char`, you need to change the code to use a character literal, like this:
grade ='A';
Problem
I am creating a class to calculate a grade for a user in C++ and I am coming across a simple yet annoying problem. I know what the errors means but I don't understand how to fix it and changing to a string actually fixes the issue but this is not what I want to do. here is the error: const char *" cannot be assigned to an entity of type "char Code ``` #include <string> using namespace std; class Gradecalc { public: Gradecalc() { mark = 0; } int getmark() { return mark; } void setmark(int inmark) { mark = inmark; } void calcgrade() { if (mark >=70) { grade = "A"; //**ERROR IS HERE** } } char getgrade() { return grade; } private: int mark; char grade; //VARIABLE IS DECLARED HERE }; ```