# error C2440: '=' : cannot convert from 'const char [2]' to 'char'

This topic is 4720 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I get this error: h:\CompSci1\calculater\Calculator.cpp(45): error C2440: '=' : cannot convert from 'const char [2]' to 'char' from this line of code: yesno = "Y"; it is declared as: char yesno;

##### Share on other sites
"k" is a string literal. It contains a null terminator at the end, hence two characters. 'k' denotes a character.

##### Share on other sites
As a side thought, it's spelled calculator. [smile]

EDIT: I see you spelled the directory name wrong but not the source file, odd. Meh.

##### Share on other sites
Well as we are nitpicking grammar.

char yesno;

Is a definition, not a declaration. =P

##### Share on other sites
Replace the line with:
yesno = 'Y';
Use single quotes for individual characters (instead of double quotes for strings).

##### Share on other sites
Quote:
 Original post by RigidBodyWell as we are nitpicking grammar.

"We" weren't; the previous nitpick was about spelling.

Quote:
 char yesno; Is a definition, not a declaration. =P

Good attempt, but actually it is the other way around. To "declare" something is to say it exists; to "define" it is to say what it is. Thus this is the declaration; yesno = 'Y' would be a definition. Although, my understanding of the word "grammar" has nothing to do with the meanings of words...

##### Share on other sites
Quote:
Original post by Zahlman
Quote:
 Original post by RigidBodyWell as we are nitpicking grammar.

"We" weren't; the previous nitpick was about spelling.

Quote:
 char yesno; Is a definition, not a declaration. =P

Good attempt, but actually it is the other way around. To "declare" something is to say it exists; to "define" it is to say what it is. Thus this is the declaration; yesno = 'Y' would be a definition. Although, my understanding of the word "grammar" has nothing to do with the meanings of words...

You are incorrect.

extern char yesno;

is a declaration.

char yesno;

is a definition.

extern char yesno = 'a';

is a definition.