Saturday, November 2, 2013

Beginner C# expected class, delegates, etc. errors math quiz

Which version of Visual Studio are you using? I downloaded your stuff from your Skydrive and it won't load in mine ... but I'm still using VS 2010 ... I suspect you've written this with VS 2012?


However, no matter ... I created a new solution and used your same Form. Your problem is that you have a lot of mis-matched curly-brackets. Fix all of those ... make sure for every { you have a }. A good way to always make sure you do that is when you write a method or an if ... always put both brackets in first, then fill in the code in-between. That way you'll be sure not to forget a bracket after the fact.


Also, you have a method name and put a ; after it. This isn't correct. You had this:



public void StartTheQuiz();
{
// Fill in the multiplication problem.
multiplicand = randomizer.Next(2, 12);
multiplier = randomizer.Next(2, 12);
timesLeftLabel.Text = multiplicand.ToString();
timesRightLabel.Text = multiplier.ToString();
product1.Value = 0;

// Start the timer.
timeLeft = 30;
timeLabel.Text = "30 seconds";
timer1.Start();
}



Note the ; on the first line. I'm sure that was just a typo, but you've got to learn to spot those. It should be this:



public void StartTheQuiz()
{
// Fill in the multiplication problem.
multiplicand = randomizer.Next(2, 12);
multiplier = randomizer.Next(2, 12);
timesLeftLabel.Text = multiplicand.ToString();
timesRightLabel.Text = multiplier.ToString();
product1.Value = 0;

// Start the timer.
timeLeft = 30;
timeLabel.Text = "30 seconds";
timer1.Start();
}





~~Bonnie Berent DeWitt [C# MVP]


http://geek-goddess-bonnie.blogspot.com


No comments:

Post a Comment