|
-
January 16th, 2010, 02:55 PM
#9
Re: Math project!
You have to declare score outside a methode. Because if you declare it within a methode, the variable will be destroid when you leave the methode and be created each time you enter the methode.. thats why in the code you have now, the only values for score you'll get is 0 or 1.
use
(also for the refreshing can you explain what you want to do a bit more? )
greetz
kristof
Code:
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 Skole_projekt_
{
public partial class FormPlus : Form
{
private int score = 0;
public FormPlus()
{
InitializeComponent();
}
float a, b, c;
private void FormPlus_Load(object sender, EventArgs e)
{
Random Nran = new Random();
int H2 = Nran.Next(1, 100);
int H1 = Nran.Next(1, 100);
int o = 0;
label1.Text = H1.ToString();
label2.Text = H2.ToString();
label3.Text = o.ToString();
}
private void button1_Click(object sender, EventArgs e)
{
a = Convert.ToInt32(label1.Text);
b = Convert.ToInt32(label2.Text);
c = a + b;
label3.Text = c.ToString();
Random Nran = new Random();
int H = Nran.Next(1, 100);
if ((textBox1.Text == c.ToString()))
{
score++;
label4.Text = score.ToString(); ;
}
}
private void label1_Click(object sender, EventArgs e)
{
}
}
}
Last edited by kristof1104; January 16th, 2010 at 03:02 PM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|