#include <iostream>
#include <random>
#include <iomanip>
#include <chrono>
#include <math.h>
//@writer 5396952 Hyeonmin LEE
using namespace std;
int guessNum(int , int*);
int guessGame();
int main() {
while(1){
if (guessGame() == -1){
break;
}
}
return 0;
}
int guessNum(int number) {
int count = 0;
int input = 1;
while(1) {
count ++;
cin >> input;
if(!cin || !(input <=1000 && input >= 1)) {
cin.clear();
cin.ignore(1001, '\n');
cout << "Invalid data type or out of range!" << endl;
cout << "Please enter right value." << endl;
}
if (input < number) {
cout << "Too low. Try again." << endl;
};
if (input > number) {
cout << "Too high. Try again." << endl;
}
if(input == number){
cout << "Excellent! You guessed the number!" << endl;
return count;
break;
}
}
//return count;
};
int guessGame(){
char again = 'n';
int logCount = log2(1000) + 1;
unsigned seed = std::chrono::system_clock::now().time_since_epoch().count();
default_random_engine engine(seed);
uniform_int_distribution<unsigned int> randomNum(1, 1000);
int number = randomNum(engine);
cout << "I have number between 1 and 1000." << endl;
cout << "Can you guess my number?" << endl;
cout << "Please type your first guess" << endl;
int checkCount = guessNum(number);
//putting the funtion in condtion, declearation calls the funtion!!! watch out!
if(checkCount < logCount){
cout << "Either you know the secret or you got lucky!" << endl;
}
else if (checkCount == logCount){
cout << "Ahah! You know the secret!" << endl;
}
else if (checkCount > logCount){
cout << "You should be able to do better!" << endl;
}
cout << "would you like to play again?(y or n)" << endl;
cin >> again;
if (again == 'n'){
return -1;
}
return 0;
}
//special thanks for my great teacher && friend, Sascha "Kevin" Brun!!!
#include <random>
#include <iomanip>
#include <chrono>
#include <math.h>
//@writer 5396952 Hyeonmin LEE
using namespace std;
int guessNum(int , int*);
int guessGame();
int main() {
while(1){
if (guessGame() == -1){
break;
}
}
return 0;
}
int guessNum(int number) {
int count = 0;
int input = 1;
while(1) {
count ++;
cin >> input;
if(!cin || !(input <=1000 && input >= 1)) {
cin.clear();
cin.ignore(1001, '\n');
cout << "Invalid data type or out of range!" << endl;
cout << "Please enter right value." << endl;
}
if (input < number) {
cout << "Too low. Try again." << endl;
};
if (input > number) {
cout << "Too high. Try again." << endl;
}
if(input == number){
cout << "Excellent! You guessed the number!" << endl;
return count;
break;
}
}
//return count;
};
int guessGame(){
char again = 'n';
int logCount = log2(1000) + 1;
unsigned seed = std::chrono::system_clock::now().time_since_epoch().count();
default_random_engine engine(seed);
uniform_int_distribution<unsigned int> randomNum(1, 1000);
int number = randomNum(engine);
cout << "I have number between 1 and 1000." << endl;
cout << "Can you guess my number?" << endl;
cout << "Please type your first guess" << endl;
int checkCount = guessNum(number);
//putting the funtion in condtion, declearation calls the funtion!!! watch out!
if(checkCount < logCount){
cout << "Either you know the secret or you got lucky!" << endl;
}
else if (checkCount == logCount){
cout << "Ahah! You know the secret!" << endl;
}
else if (checkCount > logCount){
cout << "You should be able to do better!" << endl;
}
cout << "would you like to play again?(y or n)" << endl;
cin >> again;
if (again == 'n'){
return -1;
}
return 0;
}
//special thanks for my great teacher && friend, Sascha "Kevin" Brun!!!
댓글
댓글 쓰기