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())
{
}
}
}
}
}
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With