C# Requirement 1: The application displays a new multiplication question every t
ID: 668844 • Letter: C
Question
C#
Requirement 1: The application displays a new multiplication question every time the "New" button is clicked.
Requirement 2: 10 message boxes are displays indicating the remaining time in seconds.
Requirement 3: The "Time" displayed by the application decreases by 1 until it reaches 0 sec (before the user can enter an answer).
Requirement 4: The "Score" displayed by the application increases by 20 points for every correct answer.
INSTRUCTIONS:
In the NewButton_click method, create the following:
- A random variable
- Two integer variables: var1 and var2
3. Set the values of variables var1 and var2 to random numbers smaller than 10.
4. Change the text of the PromptLabel to prompt the user to enter the product of var1 and var2.
5. Set the product variable to the product of var1 and var2.
6. Create a for loop to:
- Display 10 message boxes, each with a countdown from 10 to 1.
- Change the text of the TimeLabel to show the correct number (countdown from 10 to 1).
In the SubmitButton_Click method, add code to increase the score by 20 points for every correct answer.
8. Run your program to make sure that it works as expected.
9. Close your project and ZIP your entire project file. Then upload your project to CANVAS.
http://prntscr.com/8gurna
Explanation / Answer
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
int score,product;
public Form1()
{
InitializeComponent();
score = 0;
}
private void button1_Click(object sender, EventArgs e)
{
}
private void NewButoon_click(object sender, MouseEventArgs e)
{
Random rnd = new Random();
int i, var1, var2, product;
var1 = rnd.Next(1, 9);
var2 = rnd.Next(1, 9);
PromptLabel.Text = "Enter Product of " + var1 + "and" + var2;
product = var1 * var2;
for (i = 10; i >= 1; i--)
{
MessageBox.Show(i.ToString ());
TimeLabel.Text = i.ToString ();
System.Threading.Thread.Sleep(1000);
}
}
private void SubmitButton_Click(object sender, EventArgs e)
{
if(Convert.ToInt32 (textBox1.Text) == product)
score = score + 20;
}
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.