I am beginner in C++ and I am creating a cows and bulls(player) program. The program works by making a 2D boolean array(p) for the numbers and their position.When i try to create a new possible number sometimes it seems that when it adds the next digit by multiplying it by the proper power of 10 it adds one less(399 instead of 400).I have no idea why this is happening.Here is the code:
#include <iostream>
#include <cmath>
#include <math.h>
#include <algorithm>
#include <random>
....
random_device rd;
mt19937 gen(rd());
uniform_int_distribution<> dis(1,9);
for (int s7=0;s7<=3;s7++)
{
for (bool s1=0;s1!=1;)
{
int k=0;
bool z=0;
k=dis(gen);
for (int s8=0;s8<=3;s8++)
{
if (k==nm[s8]) z=1;
}
if (p[k][s7]==0 && z==0 && k!=0)
{
s1=1;
b=b+k*pow(10.0,s7);
cout <<k*pow(10.0,s7)<<" "<<b<<endl;
nm[s7]=k;
}
}
}
(The first few lines i got from internet) and here is the output: 1 1 50 51 900 950 2000 2950 Thank you in advance :)