Saturday, November 2, 2013

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

So...I'm self-studying some programming and decided to start with C#. I looked at the tutorials and went through the basic stuff, and when I came to the math quiz tutorial #3, I decided to live a little and make it my own (slightly). My son is working on multiplication tables in school, so I wanted to generate a small program to help him study. Therefore, I eliminated the other math (addition, subtraction, and division) and tried to replicate the code to just do multiplication problems. So far, I like the way its going, but I got some crazy ValueChanged error, and deleted some lines of code that were problematic from my product (labels?). That reduced my errors and let me bring the visual program back up in design studio, but now I'm getting these expected class errors, and I'm thinking I just don't understand what I'm doing wrong with the Void, Bool, Class stuff. Since I've changed so much code from the tut, I've kinda lost track of where to look for differences....please help!



using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Multiplication_Quiz
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

// Create a Random object to generate random numbers.
Random randomizer = new Random();

// These ints will store the numbers for the multiplication problem.
int multiplicand;
int multiplier;
int timeLeft;}

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();
}

private void answer_Enter(object sender, EventArgs e)
{
// Select the whole answer in the NumericUpDown control.
NumericUpDown answerBox = sender as NumericUpDown;

if (answerBox != null)
{
int lengthOfAnswer = answerBox.Value.ToString().Length;
answerBox.Select(0, lengthOfAnswer);
}

private void timer1_Tick(object sender, EventArgs e)
{

if (timeLeft > 0)
{
// Display the new time left
// by updating the Time Left label.
timeLeft = timeLeft - 1;
timeLabel.Text = timeLeft + " seconds";
}
else
{
// If the user ran out of time, stop the timer, show
// a MessageBox, and fill in the answers.
timer1.Stop();
timeLabel.Text = "Time's up!";
MessageBox.Show("You didn't finish in time.", "Sorry");
product1.Value = multiplicand * multiplier;
startButton.Enabled = true;
private void StartButton_Click(object sender, EventArgs e)
{

startButton.Enabled = false;
}

private void timeLabel_Click(object sender, EventArgs e)
{



/// <summary>
/// Check the answer to see if the user got everything right.
/// </summary>
/// <returns>True if the answer's correct, false otherwise.</returns>
private bool CheckTheAnswer()
{
if ((multiplicand * multiplier == product1.Value))


return true;
else
return false;
}}


No comments:

Post a Comment