Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "pch.h"
- #include <iostream>
- #include <thread>
- #include <windows.h>
- #include <string>
- using namespace std;
- //Typeracer game
- double timer = 0;
- bool end_game = false;
- void hellothere()
- {
- while (!end_game)
- {
- if (timer == 30)
- {
- end_game = true;
- system("cls");
- }
- Sleep(1000);
- timer++;
- }
- }
- char word[5];
- string input_from_player;
- void intitialize_word()
- {
- srand(time(NULL));
- for (int x = 0; x < 5; x++)
- {
- word[x] = (rand() % 25) + 97;
- }
- input_from_player = word;
- }
- int main()
- {
- intitialize_word();
- double points = 0;
- thread clock(hellothere);
- while (!end_game)
- {
- for (int k = 0; k < 5; k++)
- {
- cout << word[k];
- }
- cout << endl;
- cin >> input_from_player;
- if (input_from_player == word)
- {
- intitialize_word();
- points++;
- }
- system("cls");
- if (points == 10)
- {
- end_game = true;
- }
- }
- clock.join(); //End time
- double words_per_minute = (points/timer) * 60;
- cout << words_per_minute << endl;
- cout << "You typed 10 words over a period of " << timer << " seconds" << endl;
- cout << "This estimates to " << words_per_minute << " words per minute." << endl;
- int pause; cin >> pause; //Pause the game
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement