Number Guessing Game in C++ without global varibles Recently, I have gotten into C++. My past experience is some batch programming and beginner JavaScript/HTML. This language, unlike the others, has made me really think about the efficiency of my code. I am trying to do a beginner exercise from a C++ forum (Bracketing Searching) and make it as good as I possibly can. Can someone explain to me anything I am doing right or wrong? I also feel like this code is the most efficient, however it is really confusing to read, even for me.

#include &lt;iostream&gt; //include the input, output stream
#include &lt;Windows.h&gt; //include windows command library
#include &lt;ctime&gt; //include time library

int ask() { //ask for input and return it
    int guess;
    std::cout &lt;&lt; "Input your guess: \n";
    std::cin &gt;&gt; guess;
    return guess;
}

bool calc(int guess,int num) { //takes the guess and  the number then returns true or false accordingly
    bool hasWon = false;
    if (guess &gt; num) {
        std::cout &lt;&lt; "Too high!\n";
    }
    else if (guess &lt; num) {
        std::cout &lt;&lt; "Too low!\n";
    }
    else if (guess == num) {
        std::cout &lt;&lt; "Congrats, you are correct!\n";
        Sleep(3000);
        hasWon = true;
    }
    return hasWon;
}

void startMenu() { //Display welcome menu
    std::cout &lt;&lt; "Welcome to my game.\n";
    std::cout &lt;&lt; "I will think of a number from 1 to 100.\n";
    std::cout &lt;&lt; "Guess it!\n";
}

int makeNum() {
    srand(time(0)); //Truly random number
    int num = rand() % 100; //Generate a random Number
    return num; //return the number to the main loop
}

int main() {
    startMenu(); //Display the welcome screen
    int ranNum = makeNum(); //generate the main random number
    bool hasWon = false; //set default state of win varible

    while (hasWon != true) { //while the player has NOT won keep asking
        hasWon = calc(ask(), ranNum); //Main loop of code for asking and calculating
        }
    return 0; //Terminate program
}
rand() is bad; don't use it.

Instead, use the &lt;random&gt; library for generating random numbers:

static std::mt19937_64 engine(std::random_device{}());
std::uniform_int_distribution&lt;&gt; dist(1, 100);
std::cout &lt;&lt; dist(engine);


You'll then have:

int makeNum() {
    static std::mt19937_64 engine(std::random_device{}());
    std::uniform_int_distribution&lt;&gt; dist(1, 100);
    return dist(engine);
}

The name calc() doesn't make sense with the expected return and it doesn't even calculate anything. You can rename it to hasWon() and rename the variable to won.

Moreover, I would move the output to main() since it shouldn't really be responsible for printing to the console. Just have it do the comparison and then return the value.
Do you really need the program to sleep? It may not be worth that call, plus it prevents it from being portable to other systems. You can always use std::cin.get() to "pause" the program by asking the user to enter a character before proceeding.