Compare commits

...

5 Commits

Author SHA1 Message Date
Emojigit 7cc78abab6 compile failed fix 2021-04-08 12:53:22 +08:00
Emojigit 009eab6195 REAL more random 2021-04-08 12:47:02 +08:00
Emojigit 2f48026b5e more random 2021-04-08 12:07:20 +08:00
Emojigit aaa75156d8 add 2021-04-08 09:59:40 +08:00
Emojigit 750f183366
Create .gitignore 2021-04-08 09:36:11 +08:00
2 changed files with 49 additions and 3 deletions

32
.gitignore vendored Normal file
View File

@ -0,0 +1,32 @@
# Prerequisites
*.d
# Compiled Object files
*.slo
*.lo
*.o
*.obj
# Precompiled Headers
*.gch
*.pch
# Compiled Dynamic libraries
*.so
*.dylib
*.dll
# Fortran module files
*.mod
*.smod
# Compiled Static libraries
*.lai
*.la
*.a
*.lib
# Executables
*.exe
*.out
*.app

View File

@ -3,10 +3,13 @@
#include <cstdlib>
#include <signal.h>
#include <ctime>
#include <sys/time.h>
using namespace std;
int random_num(int lo,int hi) { // contributed by a_k_n, https://www.cplusplus.com/forum/general/107917/
srand(time(NULL));
struct timeval time_now{};
gettimeofday(&time_now, nullptr);
srand(time_now.tv_usec);
return rand()%(hi-lo) + lo;
}
@ -23,11 +26,22 @@ int main() {
cout << "Guess a 2 digit number!" << endl;
signal(SIGINT, sigint_handler);
while(1) {
cout << guess_attempt++ << " guess attempt: ";
cout << guess_attempt+1 << " guess attempt: ";
int x;
cin >> x;
++guess_attempt;
if ( x == rand_guess_int ) {
if (cin.fail()) {
cout << "INVALID NUMBER, NOT AN INT!" << endl;
std::cin.clear();
std::cin.ignore(256,'\n');
--guess_attempt;
} else if ( x < 10 ) {
cout << "INVALID NUMBER! numbers should bigger then 9" << endl;
--guess_attempt;
} else if ( x > 99 ) {
cout << "INVALID NUMBER! numbers should smaller then 100" << endl;
--guess_attempt;
} else if ( x == rand_guess_int ) {
cout << "YAY! The secret number is " << rand_guess_int << ", you success within " << guess_attempt << " attempts!" << endl;
return 0;
} else if ( x < rand_guess_int ) {