기본 콘텐츠로 건너뛰기

C++ A6 submitted file

#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!!!

댓글

이 블로그의 인기 게시물

JS 5.5 task6 Create an extendable calculator

<HTML>   <body>   </body>   <script> function Calculator() {   let methods = {     "-" : (a, b) => a - b,     "+" : (a, b) => a + b   };   //methods is an object which keeps key for operators   //and value to return the actual operation values   //each returns the result of operation that key(operator) does   this.calculate = function (str){     //calculate is one element in the function Calculator     //it takes the string and returns the value     //in the function element list is delimeted by , not ;     let split = str.split(" "),     a = +split[0],     op = split[1],     b = split [2]     if(!methods[op] || isNaN(a) || isNaN(b)) {       return NaN; // error handling     }     return methods[op](a,b);   }   this.addMethod = function(name, func){     methods[name] = func;     //this is how to add new key and ele to object   } } let powerCalc = new Calculator; powerCalc.addMethod("*&

JS 5.7 task5 Store read dates

<HTML>   <body>   </body>    <script>    let messages = [        {text: "Hello", from: "John"},        {text: "How goes?", from: "John"},        {text: "See you soon", from: "Alice"}    ];    let readMap = new WeakMap();    alert(readMap.size);    readMap.set(messages[0], new Date(2019, 3, 5));   </script> </HTML> <!-- task4 needed weakSet to save simply readmessage, this task needs to save THE TIME IT WAS READ along with the message itself the message out of the set or map means it hasn't been read I kinda feel good and bad at the same time to happen to read the solution but I do get to think more about the difference with tasks and be more available to understand the main contents so I think, its good? -->

How to set base url when deployed in Heroku? : base url and axios

https://stackoverflow.com/questions/47164330/axios-api-calls-in-heroku/47165888 baseUrl = process.env.baseURL || "http://localhost:5000" Even more stable way https://stackoverflow.com/questions/52129849/how-to-get-the-base-url-variable-on-a-deployed-heroku-node-app const production  = 'https://examplePage.com'; const development = 'http://localhost:3000/'; const url = (process.env.NODE_ENV ? production : development); process.env.NODE_ENV will resolve to undefined if you are running on localhost production mode. and return production if you have deployed the app production mode.