forked from ChicoState/tippitytappity
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
51 lines (46 loc) · 1.8 KB
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#include <iostream>
#include <chrono>
using std::cin;
using std::cout;
using std::endl;
using std::string;
int main(){
const string phrase = "The quick brown fox jumps over the lazy dog";
string input;
std::chrono::steady_clock::time_point started;
std::chrono::steady_clock::time_point stopped;
long milliseconds = 0;
do{
cout << "Type the following phrase and then press return:\n"
<< phrase << endl;
started = std::chrono::steady_clock::now(); // start timer
getline(cin,input);
stopped = std::chrono::steady_clock::now(); // stop timer
milliseconds = std::chrono::duration_cast<std::chrono::milliseconds>(stopped - started).count();
//TODO: Show results here
double percentage = phrase.size();
//cout << "percentage equals: " << percentage << endl;
double correct = 0.0;
double resultPercentage = 0.0;
if (input == phrase){
cout << "You typed everything correct! 100%!" << endl;
} else {
for (int i = 0; i < input.size(); i++) {
if (input[i] = phrase[i]) {
//cout << "Added 1 to correct" << endl;
correct++;
}
}
//cout << "Value of correct is: " << correct << endl;
//cout << "Value of percentage is: " << percentage << endl;
resultPercentage = (correct/percentage) * 100;
//cout << "Calculated Percentage is: " << correct/percentage * 100 << endl;
}
cout << "You got the phrase " << resultPercentage << " percent correct" << endl;
do{
cout << "Try again? (yes/no)\n";
getline(cin,input);
}while( input != "yes" && input != "no" );
}while( input == "yes" );
return 0;
}