Welcome to the Typing Speed Test Application. This program is designed to test how fast and accurately you can type a given sentence.
Introduction
The typing speed test application measures how quickly a user can type a given text. It calculates the words per minute (WPM) and the accuracy of typing. The goal of this application is to provide users with an easy way to measure their typing skills and improve them over time.
Objective
The main objective of this typing speed test application is to:
- Test the typing speed of users in words per minute (WPM).
- Measure the accuracy of the typed text.
- Provide a score based on both speed and accuracy.
- Help users track their typing progress over time.
C Program Code
#include #include #include void typing_speed_test() { char sentence[] = "The quick brown fox jumps over the lazy dog"; char user_input[200]; int i, correct = 0, total_chars = 0; clock_t start_time, end_time; double time_taken; printf("Typing Speed Test\n"); printf("Type the following sentence as fast and accurately as you can:\n"); printf("\"%s\"\n", sentence); printf("\nPress Enter to start...\n"); getchar(); // wait for user to press enter before starting start_time = clock(); // record start time printf("\nStart typing:\n"); fgets(user_input, sizeof(user_input), stdin); // get input from the user end_time = clock(); // record end time time_taken = (double)(end_time - start_time) / CLOCKS_PER_SEC; // calculate time taken // check accuracy for (i = 0; i < strlen(sentence); i++) { if (user_input[i] == sentence[i]) { correct++; } } total_chars = strlen(sentence); printf("\nTime taken: %.2f seconds\n", time_taken); printf("Accuracy: %.2f%%\n", (double)correct / total_chars * 100); printf("Your typing speed is: %.2f words per minute (WPM)\n", (double)total_chars / 5 / (time_taken / 60)); } int main() { typing_speed_test(); return 0; }
Explanation of the Program
The program is structured as follows:
- The program starts by displaying the sentence that the user needs to type.
- The program waits for the user to press Enter to start the test.
- Once the user starts typing, the program records the time it takes to type the sentence.
- The program then compares the user’s input with the original sentence and counts the number of correct characters.
- The program calculates the accuracy and speed (WPM) based on the results.
The typing speed is calculated by dividing the total number of characters by 5 (because a word is assumed to be 5 characters long) and then dividing the time taken (in seconds) by 60 to get the speed in words per minute.
How to Run the Program
Follow these steps to run the program:
-
- Write the provided code in a text editor and save it as
typing_speed_test.c
. - Open a terminal or command prompt and navigate to the directory where the file is saved.
- Compile the program using a C compiler, for example, using the following command:
- Write the provided code in a text editor and save it as
gcc typing_speed_test.c -o typing_speed_test
-
- Run the program using this command:
./typing_speed_test
- The program will ask you to type the given sentence, and once done, it will calculate and display your typing speed and accuracy.