Skip to content

Commit

Permalink
minor changes
Browse files Browse the repository at this point in the history
  • Loading branch information
kuashio committed Dec 5, 2022
1 parent e800510 commit e746f76
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
6 changes: 5 additions & 1 deletion src/14/Challenge/ch14_reflex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,12 @@ int main(){

std::string try_again;
std::getline(std::cin,try_again);
do{

// Write your code here
// Write your code here

std::cout << "Try again? (Y/N): " << std::flush;
std::cin >> try_again;
}while(try_again[0]=='Y' || try_again[0]=='y');
return 0;
}
14 changes: 7 additions & 7 deletions src/14/Solution/ch14_reflex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@ int main(){
std::cout << " Press Enter when you're ready to start." << std::flush;

std::string try_again;
std::getline(std::cin,try_again);
std::getline(std::cin, try_again);
std::srand((unsigned)(time(0)));
std::rand();
do{
std::string word;

int i = std::rand()%10;
std::chrono::seconds delay(4 + (int)(std::rand() / (RAND_MAX/6.0)));
std::chrono::seconds delay(4 + std::rand() % 7);

auto start = std::chrono::steady_clock::now();
auto end = start + delay;
Expand All @@ -47,24 +47,24 @@ int main(){
std::cout << "\n\t\t\t\t\t Type in the word " << words[i] << ": " << std::flush;

start = std::chrono::steady_clock::now();
std::cin >> word;
std::getline(std::cin, word);
end = std::chrono::steady_clock::now();
std::transform(word.begin(), word.end(), word.begin(), toupper);
double elapsed_seconds = (end-start).count()/1e9;
std::cout << "\n";

if(elapsed_seconds>2.0)
if(word.compare(words[i])==0)
if(elapsed_seconds > 2.0)
if(word.compare(words[i]) == 0)
std::cout << "You typed in the right word, but you took too long to react! Try again, you can do better than " << elapsed_seconds << " seconds.\n\n";
else
std::cout << "You took too long to react and typed in the wrong word! Try again. For the record, it took you " << elapsed_seconds << " seconds.\n\n";
else
if(word.compare(words[i])==0)
if(word.compare(words[i]) == 0)
std::cout << "Well done! It took you " << elapsed_seconds << " seconds.\n\n";
else
std::cout << "It took you " << elapsed_seconds << " seconds, but you typed in the wrong word! Try again.\n\n";
std::cout << "Try again? (Y/N): " << std::flush;
std::cin >> try_again;
std::getline(std::cin, try_again);
}while(try_again[0]=='Y' || try_again[0]=='y');
return 0;
}

0 comments on commit e746f76

Please sign in to comment.