error please help urgently

I am trying to compile this program but it is showing errors
I am using Microsoft Visual Studio 2006 standard edition.
This is my source code:


-------------------------------------------------
#include <iostream>
#include <conio.h>

using namespace std;

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.

03 conio_words.obj - 4 error(s), 0 warning(s)

---------------------------------------------------------

Please help me what should do get it right

Parjanya
" " is a string (const char*). Use ' ' if you want a character (the space character).
@Peter87

thaks i did that and now i shows :

---------------------------------------------------------------------------

--------------------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]'
------------------------------------------------------------------------------------

i don't understand what happened...........
You have the same problem in the loop condition with \r.
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.
Topic archived. No new replies allowed.