Question
C++ language Can't figure out why it doesn't generate a random number /* Two integers are digit-equal if the sum of their digits are equal.
C++ language Can't figure out why it doesn't generate a random number /*
Two integers are digit-equal if the sum of their digits are equal.
Write a program that generates 2 random numbers between 1 and 100000 and determines if the two numbers are digit-equal.
The program displays messages that say whether the numbers are digit-equal or not.
e.g.
6 and 123 are digit equal
14582 and 299 are digit equal
33 and 121 are not digit equal
*/
#include
#include
#include
using namespace std;
default_random_engine(e);
uniform_int_distribution
int number = u(e);
int number2 = u(e);
int main()
{
int digit1 = number % 10;
int newNumber = number / 10;
int digit2 = newNumber % 10;
int newNumber2 = newNumber / 10;
int digit3 = newNumber2 % 10;
int newNumber3 = newNumber2 / 10;
int digit4 = newNumber3 % 10;
int newNumber4 = newNumber3 / 10;
int digit5 = newNumber4 % 10;
int newNumber5 = newNumber4 / 10;
int digit6 = newNumber5 / 10;
int sumOne = digit1 + digit2 + digit3 + digit4 + digit5 + digit6;
cout << " The first number is " << number << endl;
cout << " The sum of the first numbers digits is: " << sumOne << endl;
int digit01 = number2 % 10;
int newNumber0 = number2 / 10;
int digit02 = newNumber0 % 10;
int newNumber02 = newNumber0 % 10;
int digit03 = newNumber02 % 10;
int newNumber03 = newNumber02 / 10;
int digit04 = newNumber03 % 10;
int newNumber04 = newNumber03 / 10;
int digit05 = newNumber04 % 10;
int newNumber05 = newNumber04 / 10;
int digit06 = newNumber05 % 10;
int sumTwo = digit01 + digit02 + digit03 + digit04 + digit05 + digit06;
cout << " The second number is " << number2 << endl;
cout << " The sum of the digits of the second number is: " << sumTwo << endl;
if (sumOne == sumTwo) {
cout << " The two numbers are digit equal. " << endl;
}
else
cout << " The two numbers are not digit equal. " << endl;
system("pause");
return 0;
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started