Friday, October 11, 2013

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


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;

// This will show the time left
int timeLeft;


private void StartButton_Click(object sender, EventArgs e)
{
startButton.Enabled = false;
}


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 = 60;
timeLabel.Text = "60 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 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()
{
return multiplicand * multiplier == product1.Value;
}

private void timer1_Tick_1(object sender, EventArgs e)
{

}
}
}






No comments:

Post a Comment