QUOTE
How does the timer f**k up? What problems are you having. Its a good thing you posted your code, but we need a detailed explanation of whats going wrong
Sorry about the swearing I hope it didnt offend anyone (just a bit frassled over this, cant figure out what im doing wrong).
Ok some images would be better at describing the issue:

Thats how it's meant to work. Explanation of how i intended it to work is in the first post.

Thats the error.
It seems to occur randomly.
It adds alot of extra dp. These extra decimal points appear to be increasing. Its counting something entirely different to the time and appears to be a completely different counter altogether thats strangely attached to the time counter.
I hope I explained clearly enough (if not try the program for yourself and it will occur at least once per game).
A friend Suggested that it may be a problem with the rest of the code but I dont think so, but just to be safe here it is:
csharp
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace WindowsApplication1
{
public partial class Form1 : Form
{
//Declaring variables
double guesses = 6; //Number of Guesses
private Random rndNum;
string inputString;
double inputDouble;
int rndNumInt;
double timerDouble = 0.0;
string timerString;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
//Form loading
//Creating a random number and converting it into an integer
rndNum = new Random();
rndNumInt = Convert.ToInt32(rndNum.Next(1, 101));
}
private void guessbtn_Click(object sender, EventArgs e)
{
//Receiving the guess from the numbertxt textbox and varifying
inputString = numbertxt.Text;
if (inputString == "")
{
MessageBox.Show("Please input a number between 0 and 100.");
goto found;
}
inputDouble = Convert.ToDouble(inputString);
//Starting timer
timertmr.Enabled = true;
//Calculating if the guess was correct
if (inputDouble > 100)
MessageBox.Show("Please input a number between 0 and 100.");
else
if (inputDouble < 0)
MessageBox.Show("Please input a number between 0 and 100.");
else
if (inputDouble > rndNumInt)
resultstxt.Text = "Lower";
else
if (inputDouble < rndNumInt)
resultstxt.Text = "Higher";
else
resultstxt.Text = "Correct!";
//Actions taken if guess is correct
if (resultstxt.Text == "Correct!")
{
ProgramEnd();
}
//Processing how many guesses are left and what actions to take
guesses = guesses - 1;
guesseslbl.Text = ("You have " + Convert.ToString(guesses) + " guesses remaining.");
if (guesses == 0)
if (resultstxt.Text != "Correct!")
{
ProgramEnd();
resultstxt.Text = "Failure!";
MessageBox.Show("Sorry, the correct number was " + Convert.ToString(rndNumInt));
}
found: ;
}
private void ProgramRestart()
{
//Restarting the program
rndNum = new Random();
rndNumInt = Convert.ToInt32(rndNum.Next(1, 101));
numbertxt.Text = "";
resultstxt.Text = "";
guesses = 6;
guessbtn.Enabled = true;
numbertxt.Enabled = true;
restartbtn.Visible = false;
exitbtn.Visible = false;
name1lbl.Visible = false;
name2lbl.Visible = false;
restartmnu.Enabled = false;
exitmnu.Enabled = false;
}
private void ProgramEnd()
{
//Disabling most features but allowing restart and exit
guessbtn.Enabled = false;
timertmr.Enabled = false;
numbertxt.Enabled = false;
restartbtn.Visible = true;
exitbtn.Visible = true;
name1lbl.Visible = true;
name2lbl.Visible = true;
restartmnu.Enabled = true;
exitmnu.Enabled = true;
}
private void exitbtn_Click(object sender, EventArgs e)
{
//Closing down the program
Close();
}
private void restartmnu_Click(object sender, EventArgs e)
{
//Executing ProgramRestart method
ProgramRestart();
}
private void exitmnu_Click(object sender, EventArgs e)
{
//Closing down the program
Close();
}
private void restartbtn_Click(object sender, EventArgs e)
{
//Executing ProgramRestart method
ProgramRestart();
}
private void timertmr_Tick(object sender, EventArgs e)
{
//Calculating and displaying timer
timerDouble = timerDouble + 0.1;
timerString = Convert.ToString(timerDouble);
timerlbl.Text = "Timer: " + timerDouble;
}
private void numbertxt_Click(object sender, EventArgs e)
{
//Reseting numbertxt box when clicked
numbertxt.Text = "";
}
}
}
I have intentionally made it that the exit button and restart button do not work during a guess game (works after the game) so use alt+f4 to exit or wait till you finish the game. The timer not resetting after each game is also intentional.
Thank You very much for your time
P.S This isn't homework or anything so help others who need it first.
I am a health science student at the University of Otago (in New Zealand) trying to get into medicine. I am trying to learn C sharp programming as a side activity. Unfortunately, I dont have any help as im not actually doing a Computing course so most of my knowledge is from programming books and online tutorials, which have not been able to help with this particular problem. I have racked my brain over it for weeks and have given up and hoping to find some help. So it's really not urgent.
This post has been edited by Mantis1: 11 Mar, 2008 - 02:57 PM