Programming typing speed test c++?

Im stuck on my program that i need to do. Im asked to type in this sentence and then i need to have it say how many seconds did it take to type in the sentence. If you know how to do this can you help point me in the right direction. I dont need to worry about the errors in the sentence just the speed.


well thats sort of what i want i tried to compile that it didnt work. I all ready started a program but im having problems compiling it im getting a error. 'operator-'not implemented in type 'Time' for arguments of the same type in function main

4 Answers

  • 1 decade ago
    Favorite Answer

    The answers above ought to do the trick. Some additional info: For a *real* speed test, you would probably want to compute the edit distance between the actual string and the string the user typed (or some similar measure), and use that along with time to compute the score. Algorithms for edit distance can be found through normal internet searches for which the top hit will most likely be wikipedia.

  • oops
    Lv 6
    1 decade ago

    #include <string>

    #include <iostream>

    #include <ctime>

    using namespace std;

    int main()


        string sentence;

        clock_t start, end;

        start = clock();

        cin >> sentence;

        end = clock();

        double seconds = (double)(end - start) / CLOCKS_PER_SEC;

        cout << "Typing the sentence took " << seconds << " seconds.";


    Edit: Are you referencing my code in your additional details? Because if you tried this code, you could not have got any errors, as this is error free C++. If you got errors with this code, either you copied it wrong, or there's something wrong with your compiler.

  • 1 decade ago

    1. take the time

    2. ask for the user to type the sentence

    3. take the time again

    4. subtract 1 from 3.

    5. DING! print the result

  • pattie
    Lv 4
    4 years ago

    Would like to find out more about this as well

Still have questions? Get your answers by asking now.