Broken timer

Hello, I'm working on a game for a schoolproject and have encountered an error.
this is my code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#include "outpu.h"
#include <time.h>
#include <string>
#include <iostream>
#include <conio.h>
using namespace std;

void textout(string text)
{
	srand(time(NULL));
	long lengte = text.size();
	float cntr;
	int randomget;
	clock_t btime;
	clock_t t;
	bool br=false;
	for (int b=0; b < lengte; b++)
	{
		randomget = 100 - (rand() % 50);
		cout << text.substr(b, 1);
		cntr = randomget / 10000.0;
		btime = clock();
		t = clock()-btime;
		while ((t) / CLOCKS_PER_SEC < cntr)
		{
			if (_kbhit())
				br = true;
			t = clock() - btime;
			if (br)
				break;
		}
		if (br)
		{
			cout << text.substr(b + 1, (lengte - (b + 1)));
			break;
		}
	}
}

and I think it should work, but it takes way too long in between letters...
any help?
also I wonder if it's possible to get the program to notice the key hit, but not save that data to cin
Last edited on
Topic archived. No new replies allowed.