Thread: Cant fix this

  1. #1
    Registered User
    Join Date
    May 2012
    Posts
    17

    Cant fix this

    Code:
     if(CheckValidInput(intTemp)==true)
                {
                    intNumberofTries++;
                    numTriesLabel.Text=intNumberofTries.ToString();
                    if((intNumberofTries>8)||(blnSuccess==true))
                    {
                        blnStartFlag=false;
                        messageLabel.Text="The Game has already ended.\nClick the Start button for another game";
                    }
                    else
                    {
                        intStatus = CompareWithNumber(intTemp);
                        if(intStatus==0)
                        {
                            messageLabel.Text="Congratulation! It's Correct";
                            blnSuccess=true;
                        }
                        else if(intStatus==-1)
                            messageLabel.Text="Too Low!!!";
                        else
                            messageLabel.Text="Too Hard!!!";
                    }
                }
    Been trying to fix that purple part for ages. VS says: Operators "==" cannot be applied to operands of type 'object' and 'bool'.

    Any idea what I can do to fix it?

  2. #2
    SAMARAS std10093's Avatar
    Join Date
    Jan 2011
    Location
    Nice, France
    Posts
    2,694
    I suppose, CheckValidInput is a function returning an object (which might be a class of yours).

    On the right sight of the operator, you have something that is is type bool. How should the compiler compare them??? Of course he doesn't know, neither do I.

    What you should do, is to overload the operator, on order to say to the compiler how to compare them. Or, I suppose that your class has a data member of type bool, which is really what you want to compare. So, you should have a public accessor, which returns this bool data member.
    Code - functions and small libraries I use


    It’s 2014 and I still use printf() for debugging.


    "Programs must be written for people to read, and only incidentally for machines to execute. " —Harold Abelson

Popular pages Recent additions subscribe to a feed