I recently got to a certain exercise in a book I am reading, and am looking for feedback. It is a program in which the user picks a number and the computer uses algorithms to guess it. If there is any way that I can improve my code, feedback is really appreciated!#include <iostream>#include <string>#include <cstdlib>#include <ctime>using namespace std;int main(){    srand(static_cast<unsigned int>(time(0))); //seed random number generator    int compNumber = rand() % 100 + 1;    int yourNumber;    cout << Please input a number between 1 and 100 << endl;    cin >> yourNumber;    cout << Ok! I'm gonna try to guess it! << endl;    while (compNumber != yourNumber)    {        if (compNumber > yourNumber)        {            do            {                --compNumber;            } while (compNumber != yourNumber);        }        else if (compNumber > yourNumber)        {            do            {                ++compNumber;            } while (compNumber != yourNumber);        }    }    cout << I guessed it! Your number is  << compNumber << endl;    return 0;}
Reverse Guess the Number program
c++;number guessing game
Sure this generates a random number from 1 -> 100.int compNumber = rand() % 100 + 1;BUT not all the numbers have an even probability. Assuming RAND_MAX is 32768 (a common value). Then the number 1->68 have a slightly higher probability than the number 69->100.To get an even distribution you need to compensate for this:int compNumberdo{    compNumber = rand();}while (compNumber > (RAND_MAX / 100 * 100));compNumber = compNumber % 100 + 1;Better yet learn to use the modern random number generator that is built into C++.// I have not tested this.// Just copied and pasted from: http://stackoverflow.com/a/19666713/14065// This is the modern equivalent of srand()std::random_device rd;std::mt19937 mt(rd());std::uniform_real_distribution<int> dist(1, 100);// Then usage is.// equivalent of rand().std::cout << dist(mt) << \n;This does not look correct:    if      (compNumber > yourNumber)    {}    else if (compNumber > yourNumber)    {}The conditions look the same to me.This does not look like guessing.        do        {            --compNumber;        } while (compNumber != yourNumber);This looks like the computer counting down until it reaches your number.