November 30th, 2011, 07:46 AM
[Resolved] Cannot implicitly convert type "string" to "int"
Since I'm still fairly new to C#, I decided to go back to the basics.
Here I have a fairly simple problem with a basic number game I'm programming in C#. Basically, the game will generate a random number and if the user guesses the correct number, it will state that the user has won. Otherwise, it tells the user that it must guess again and it restarts the program.
This is the source code so far. I have just one bug and it's the classic "cannot implicitly convert type "string" to "int" bug. "Guess" is a string, but the program has to decide whether it equals the randomly generated number. I tried implementing a ConvertToInt32 statement but it did nothing. Can anybody help me with this?
static void Main(string args)
rand = new Random();
number = rand.Next(1, 3);
Console.WriteLine("Guess the number from 1 to 3.");
guess = Console.ReadLine();
if (guess = number)
Console.WriteLine("Sorry, guess again.");
} while (guess != "Q");
Last edited by Krunchyman; December 7th, 2011 at 09:34 AM.
Tags for this Thread
Click Here to Expand Forum to Full Width
This is a Codeguru.com survey!