I writing a code that generate two random integer and display the result of dividing the first number by the second. I want the first integer to be more than the second integer and the result of the division without remainder (an integer number)
I tried using do while loop and continue to change the integers until it generate the numbers as I wanted.
std::random_device device;
std::mt19937 rd(device());
std::uniform_int_distribution<int> random(1, 100);
int firstNumber;
int secondNumber;
do
{
firstNumber = random(rd);
secondNumber = random(rd);
}
while ((firstNumber < secondNumber) && (firstNumber % secondNumber != 0));
int result = firstNumber / secondNumber;
//print the integer to check it
std::cout << firstNumber << std::endl;
std::cout << secondNumber << std::endl;
each time I run this code it always give me the first integer more than the second. but the division result will be with remainder
Aucun commentaire:
Enregistrer un commentaire