"Type This" Game

Write your question here.
I am a beginner at C++ and I need help regarding a certain program I must make:

I would like to be able to make a type this game that does the following:
You have 1000 points in the beginning of the game. Starting with 5 randomly generated letters being mixed with lower and upper cases, you need to type them correctly within 5000 msec. If you succeed in three consecutive rounds, no matter you made them within the interval or not, you will proceed for the harder round of one more letter (6 letters) within 250 msec shorter duration (4750 msec). You will get 100 points every time you produce the matching string within the interval. No point will be given if exceeding the time interval, even reproducing the right string. The challenge becomes increasingly difficult after the successful match of three rounds (within the interval or not), e.g., 9 letters to type within 4000 msec.

If you misspell, you will be penalized by the total offset of mistaken letters. You will loose this offset from your points. The offset is computed by accumulating the absolute distance between two characters in the same position, one from the generated string and another from the input. For instance, the offset of "Game" and "Mag" is 81. The shorter string is padded with space(s). Therefore, |G - M| = 6, |a - a| = 0, |m - g| = 6, |e - (space)| = 69. If you misspell and overtime, you will be penalized the double score of the offset. Making three consecutive errors will reverse the challenge, i.e., 1 letter less and 250 msec more interval. Game ends when you type "end" or reaching negative points.

This is what I have so far but none of this compiles and I need help finding how I can fix these functions to do what the problem is asking.

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
39
40
41
42
 
#include <iostream>
#include <cstdlib>
#include <ctime>
#include <string>

using namespace std;

static const char letters[]="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";

int string_length = sizeof(letters) -1;
char genRandom(){
	return letters[rand()%string_length];
}

int main (){
	srand(time(0));
		for (int i=0; i<5; i++) {
			cout<<genRandom();
	}
//for input
string word = "";
    while (true)
    {
        cout << "Please enter a 5 letter word: ";
        getline(cin, word);

        if(word.length() == 5)
            if(isalpha(word[0]) && isalpha(word[1]) && isalpha(word[2]) && isalpha(word[3])&& isalpha(word[4]))

        cout << "Invalid input, please try again" << endl;
    }
//for time
int n=1000000;
		auto t1=system_clock::now();
		for (int i=0; i<n;i++) do_something();
		auto t2=system_clock::now();
		cout<<"do_something"<<n<<"time took"<<duration_cast<milliseconds>(t2-t1).count()<<"milliseconds\n";
return 0;
}

closed account (48bpfSEw)
Running your code in http://cpp.sh/ produces a lot of errors!

The compiler sayes what is wrong with your code and at which position the error occured:

In function 'int main()':

34:11: error: 'system_clock' has not been declared

35:39: error: 'do_something' was not declared in this scope

36:11: error: 'system_clock' has not been declared

37:41: error: 'duration_cast' was not declared in this scope

37:55: error: 'milliseconds' was not declared in this scope


start with the first error and find out why "system_clock" is not declared!
search with google for "time cpp" or look at your books about c++


good luck! ^^

Topic archived. No new replies allowed.