operand types are incompatible

Hi guys,
I am trying to learn and follow through a book. I have some basic code from the the book however it keeps throwing me the following error:

cannot convert from const char [2] to char (see the line "if (c == "a") )

I would have thought that being from a published book, it should work.
The code is:

#include <iostream>
using namespace std;

#include "Inequalities.hpp"

int main()
{
double d1, d2;
cout << "Enter the first number: ";
cin >> d1;
cout << "Enter the second number: ";
cin >> d2;

char c;
cout << "What do you want to know: a) Max or b) Min ? ";
cin >> c;
if (c == "a")
{
cout << "Max value is: " << Max(d1, d2) << endl;
}
else
{
cout << "Min value is: " << Min(d1, d2) << endl;
}
double dA = 1.0; double dB = 2.0; double dC = 3.0;
cout << "\n\n Max and Min of three numbers: " << endl;
cout << "Max value is: " << Max(dA, dB, dC) << endl;
cout << "Min value is: " << Min(dA, dB, dC) << endl;

return 0;
}


Can someone please explain why the == operator does not seem to work?

Cheers
Last edited on
c is a character. "a" is a string.

If you want to compare with a character, use single quotes like so: 'a'.
Topic archived. No new replies allowed.