Advertisement
KeeganT

Typing Game!

Sep 14th, 2018
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.14 KB | None | 0 0
  1. #include <iostream>
  2. #include <windows.h>
  3. #include <chrono>
  4.  
  5. using namespace std;
  6.  
  7. int main()
  8. {
  9.     string text;
  10.     string quote="Perhaps if you know you are insane then you are not insane.";
  11.     float wordCount=1;
  12.     for(int c=0;c<quote.length();c++)if(quote[c]==' '&&quote[c+1]!=' ')wordCount++;
  13.     cout<<quote<<endl;
  14.     for(int c=3;c>0;c--)
  15.     {
  16.         cout<<c;
  17.         Sleep(1000);
  18.         system("cls");
  19.         cout<<quote<<endl;
  20.     }
  21.     auto start=chrono::high_resolution_clock::now();
  22.     getline(cin,text);
  23.     auto finish=chrono::high_resolution_clock::now();
  24.     chrono::duration<double>elapsed=finish-start;
  25.     float time=elapsed.count();
  26.     bool acc=false;
  27.     if(text==quote)acc=true;
  28.     if(acc==true)
  29.     {
  30.         float wpm=(wordCount/time)*60;
  31.         float cpm=wpm*5;
  32.         cout<<"Your time was: ";
  33.         printf("%.2f",time);
  34.         cout<<" seconds."<<endl;
  35.         cout<<"That's ";
  36.         printf("%.0f",wpm);
  37.         cout<<" words per minute! (";
  38.         printf("%.0f",cpm);
  39.         cout<<" CPM).";
  40.     }
  41.     if(acc==false)cout<<"You made a mistake. Restart the program and try again.";
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement