So this is a small part of a bigger project I'm working on. I'm having trouble with having a visual countdown starting from a value the user inputs. I have three elements on the form textBox1 where the user enters the value to start from and label1 where the visual countdown should take place. The button1 will start the countdown. When I run the program and click on the button the countdown will start and finish correctly by displaying Done in the textBox1 and 0 in label1 but during the countdown label1 did not show 9..8..7...6..5...4...3....2..1..0.
I also tried my program in win32 Console Application with cout and it worked perfectly fine. Can some one explain to me why it will not work in a GUI.
Here is my code for the button1 and the function wait(), I'm also using #include <time.h>
void wait ( int seconds )
{
clock_t endwait;
endwait = clock () + seconds * CLOCKS_PER_SEC ;
while (clock() < endwait) {}
}
private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {
Int32 i=Convert::ToInt32(textBox1->Text);
for (Int32 n=i; n>0; n--)
{
i--;
wait (1);
label1->Text=i.ToString();
}
if(i<=0)
{
textBox1->Text="Done";
}
}