Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot implicitly convert type 'int' to 'bool' [duplicate]

Tags:

c#

Possible Duplicate:
Help converting type - cannot implicitly convert type ‘string’ to ‘bool’

I am very new to the language n I am not a good programmer. This code is giving me error:

cannot implicitly convert type int to bool.

I am not sure what I am doing wrong. Can some tell me what I am doing wrong. Any help would be appreciated n any recomendation would also help.

 using System;
 using System.Collections.Generic;
 using System.Linq;
 using System.Text;

   namespace ConsoleApplication2
   {
     class mysteryVal
  {
   public const int limitOfGuess = 5;

  // Data member
    public int mystVal;
         private int numOfGuess ;
      private randomNumberMagnifier mag = new randomNumberMagnifier();

      public int randomMag(int num)
     {
        return num + mystVal;
      }

     // Instance Constructor
     public mysteryVal()
     {
        mystVal = 0;
         numOfGuess = 0;
            }

           public void game(int user)
          {
              int userInput = user;
               if (numOfGuess < limitOfGuess)
                     {
                  numOfGuess++;
                 if (userInput = mag.randomMagnifier())
                   {
                }
               }

           } 


           }
                } 
like image 890
user1730332 Avatar asked Oct 12 '12 02:10

user1730332


1 Answers

Correct this:

if (userInput = mag.randomMagnifier())

to:

if (userInput == mag.randomMagnifier())

Here you are assigning the value in the if statement, which is wrong. You have to check the condition, for checking condition u have to use "==".
if statement returns boolean values, and because you are assigning value here, it's giving the error.

like image 73
Ravindra Bagale Avatar answered Sep 19 '22 10:09

Ravindra Bagale