eng
competition

Text Practice Mode

c++ codeeeeeeeeee

created Jan 5th, 20:01 by Bshara


1


Rating

170 words
3 completed
00:00
#include <iostream>   
#include <string>   
#include <chrono>   
 
using namespace std;   
 
int main() {   
    // Sample sentence for typing practice   
    string sampleText = "The quick brown fox jumps over the lazy dog.";   
    string userInput;   
 
    cout << "Typing Trainer" << endl;   
    cout << "Type the following sentence:" << endl;   
    cout << sampleText << endl;   
 
    // Start timing   
    auto startTime = chrono::high_resolution_clock::now();   
 
    // Get user input   
    getline(cin, userInput);   
 
    // Stop timing   
    auto endTime = chrono::high_resolution_clock::now();   
    chrono::duration<double> elapsed = endTime - startTime;   
 
    // Calculate typing speed   
    int wordCount = 0;   
    for (char c : userInput) {   
        if (c == ' ') {   
            wordCount++;   
        }   
    }   
    // Add one for the last word   
    wordCount += 1;   
 
    // Convert elapsed time to minutes   
    double elapsedMinutes = elapsed.count() / 60.0;   
    double wpm = wordCount / elapsedMinutes;   
 
    // Display results   
    cout << "\nTime taken: " << elapsed.count() << " seconds." << endl;   
    cout << "Words typed: " << wordCount << endl;   
    cout << "Typing speed: " << wpm << " words per minute." << endl;   
 
    return 0;   
}   

saving score / loading statistics ...