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.
Firstly ch should be a char and not an integer...
You should consider replacing the double quotation mark with a single one (ie: instead of "\r" use '\r' -- line 11 and instead of " " use ' ' -- line 13).
However, I also recommend moving the assignment from line 11 ch = getche() to, let's say, line 10.