Toggle does not work. (resets default value)

Ok, this works the way i want it to, it refreshes every 5 seconds (i hope) but my problem is when i click home, the loop seems to restart and "ON" reverts to "OFF"

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include <string>
#include <iostream>
#include <ctime>
#include <Windows.h>

using namespace std;

int main ()
{
	string healthStatus;
	int oneTMR = clock();
	while(!GetAsyncKeyState(VK_INSERT))
	{
		while(clock() - oneTMR > 100)
		{
	healthStatus = (GetAsyncKeyState(VK_HOME) == true ? "ON":"OFF");
	cout << " Health Status: " << healthStatus << endl;
	Sleep(500);
	system("CLS");
	}
	}
}
I can't quite see what you're trying to achieve here, from the naming it looks like you want to check for a key while insert is not pressed every 100 or so ms, then halt for half a second randomly and then clear the screen.

It could be put so much more simply, in doing so, it'll likely fix the logic. It's a very strange code sample semantically.
Topic archived. No new replies allowed.