void main()
{
int ch;
int chcnt = 0;
int wdcnt = 1;
while ((ch = getche()) != "\r")
{
if (ch == " ")
wdcnt++;
else
chcnt++;
}
std::cout << "No of Character Entered : " << chcnt << "\n";
std::cout << "No of Words Entered : " << wdcnt << "\n";
}
----------------------------------------------------------------
On compiling it shows this error :
Compiling...
03 conio_words.cpp
F:\00 C++Study 13\03 Home-Work Exercise\chapter10 Functions\examples\03 conio words\03 conio_words.cpp(11) : error C2446: '!=' : no conversion from 'char *' to 'int'
This conversion requires a reinterpret_cast, a C-style cast or function-style cast
F:\00 C++Study 13\03 Home-Work Exercise\chapter10 Functions\examples\03 conio words\03 conio_words.cpp(11) : error C2040: '!=' : 'int' differs in levels of indirection from 'char [2]'
F:\00 C++Study 13\03 Home-Work Exercise\chapter10 Functions\examples\03 conio words\03 conio_words.cpp(13) : error C2446: '==' : no conversion from 'char *' to 'int'
This conversion requires a reinterpret_cast, a C-style cast or function-style cast
F:\00 C++Study 13\03 Home-Work Exercise\chapter10 Functions\examples\03 conio words\03 conio_words.cpp(13) : error C2040: '==' : 'int' differs in levels of indirection from 'char [2]'
Error executing cl.exe.
--------------------Configuration: 03 conio_words - Win32 Debug--------------------
Compiling...
03 conio_words.cpp
: error C2446: '!=' : no conversion from 'char *' to 'int'
This conversion requires a reinterpret_cast, a C-style cast or function-style cast
: error C2040: '!=' : 'int' differs in levels of indirection from 'char [2]'
------------------------------------------------------------------------------------
First of all it is int main not void. Secondly that is a very simple error look how you have defined as an int. then you are trying to set it to a char. It may work because chars are really just ints but when you output it you will get a number and not a char. I would change it to a char instead of an int.