Build error: "const char * to int"

Hi all,

I am an absolute newbie at C++, so be gentle ;)

I have written this code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
// TestInequalities.cpp
#include <iostream> // Console input and output
using namespace std;
#include "Inequalities.h"
	
int main()
	{
	// Prompt the user for input. Console output (cout)
	// and input (cin)
	double d1, d2;
	cout << "Give the first number: ";
	cin >> d1;
	cout << "Give the second number: ";
	cin >> d2;
	char c; // Character type
	cout << "Which function 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\ nMax 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;
}


I am using Visual Studio 2010 Express. There is a red line underneath the "==". When I mouse over this I get the message:

Error: Operand types are incompatible

I am working from a book I have bought and have made sure (100 times) that the code is exactly as it is in the book.

Do you have any suggestions as to what I have done wrong?

Thanks

Chris
line 18: "a" is a string change that to 'a' (note single quotation marks) to compare to a char
Last edited on
Comparing a 'char' to a literal (line 18) requires single quotes ' ', not double quotes " " around the literal.
Wow thanks for the quick response guys, solved it!

The book has a typo in it.

thanks

Chris
Topic archived. No new replies allowed.