Search code examples
c++14

error: invalid conversion from 'const char*' to 'char' [-fpermissive]


I'm beginner to C++ programming. Whenever I run my code I got this error, but I don't know where the problem is. I declare "char" but in the error its showing that its a "const char". Tell me where I made the mistake.

#include <iostream>
using std::cout;
using std::cin;
using std::endl;
int main(){
    int score{};
    cout << "Enter the score you got(0 - 100): ";
    cin >> score;
    
    char grade{};
    if(score>=0 && score<=100){
      if(score >= 90)
          grade = "O";
      else if(score >= 80)
          grade = "A";
      else if(score >= 70)
          grade = "B";
      else if(score >= 60)
          grade = "C";
      else if(score >= 50)
          grade = "D";
      else
          grade = "F";
      cout << "Your grade is: " << grade << endl;
      
      if(grade == 'F')
          cout << "Sorry, you should give it a try again" << endl;
      else
          cout << "Well done!" << endl;
    }else{
        cout << "Sorry, the score you entered is not in range." << endl;
    }
    return 0;
}

Solution

  • Actually you try to equate char g to "0","F" and so on, that has type const char*. May be you mean g = 'F'?