Introduction

A typing speed test application is a tool used to measure the speed and accuracy of a person’s typing skills. It works by displaying a sample text, and the user needs to type it as fast as possible. The application then calculates how fast the user types, typically measured in words per minute (WPM), and also tracks accuracy.

Objective

The objective of this project is to create a simple typing speed test application in C++ that will allow users to measure their typing speed in terms of words per minute and accuracy. The program will present a randomly selected text to the user, ask them to type it, and calculate their typing speed based on the time taken.

C++ Code for Typing Speed Test

#include 
#include 
#include 
#include 
#include 

using namespace std;

int main() {
    string testText = "The quick brown fox jumps over the lazy dog";
    string userInput;
    int correctCount = 0;

    cout << "Typing Speed Test\n";
    cout << "Type the following text as fast as you can:\n";
    cout << "\"" << testText << "\"\n";
    
    // Give user time to prepare
    this_thread::sleep_for(chrono::seconds(3));
    
    auto start = chrono::high_resolution_clock::now();
    
    // Get user input
    cout << "Start Typing: ";
    getline(cin, userInput);
    
    auto end = chrono::high_resolution_clock::now();
    
    // Calculate time taken
    chrono::duration elapsed = end - start;
    double timeTaken = elapsed.count();
    
    // Calculate accuracy and words per minute
    for (size_t i = 0; i < testText.length() && i < userInput.length(); i++) {
        if (testText[i] == userInput[i]) {
            correctCount++;
        }
    }
    
    double accuracy = (double(correctCount) / testText.length()) * 100;
    double wordsPerMinute = (testText.length() / 5.0) / (timeTaken / 60.0);
    
    // Output results
    cout << "\nResults:\n";
    cout << "Time Taken: " << timeTaken << " seconds\n";
    cout << "Words per Minute: " << wordsPerMinute << " WPM\n";
    cout << "Accuracy: " << accuracy << "%\n";
    
    return 0;
}

Explanation of the Program Structure

The program starts by displaying the text that the user has to type. A 3-second preparation time is given to the user before they start typing. The program then tracks the time taken for the user to complete typing the text.

The program calculates the typing speed in words per minute (WPM) by dividing the length of the text by 5 (average number of characters in a word) and dividing that by the time taken in minutes. The accuracy is calculated by comparing each character typed by the user with the corresponding character in the displayed text.

Once the user has typed the text, the program outputs the time taken to type, words per minute, and typing accuracy in percentage.

How to Run the Program

  1. Install a C++ compiler like GCC (GNU Compiler Collection) or use an online C++ compiler.
  2. Copy the provided C++ code into a new file, for example, typing_speed_test.cpp.
  3. Compile the program. For example, using GCC, you can run the following command in your terminal:
    g++ typing_speed_test.cpp -o typing_speed_test
  4. Run the compiled program:
    ./typing_speed_test
  5. The program will display a text for you to type, and after typing, it will show your typing speed and accuracy.
© 2025 Learn Programming. All rights reserved.

 

By Aditya Bhuyan

I work as a cloud specialist. In addition to being an architect and SRE specialist, I work as a cloud engineer and developer. I have assisted my clients in converting their antiquated programmes into contemporary microservices that operate on various cloud computing platforms such as AWS, GCP, Azure, or VMware Tanzu, as well as orchestration systems such as Docker Swarm or Kubernetes. For over twenty years, I have been employed in the IT sector as a Java developer, J2EE architect, scrum master, and instructor. I write about Cloud Native and Cloud often. Bangalore, India is where my family and I call home. I maintain my physical and mental fitness by doing a lot of yoga and meditation.

Leave a Reply

Your email address will not be published. Required fields are marked *

error

Enjoy this blog? Please spread the word :)