Subtraction Problems - Both operands should be random numbers in the range, 1 to 999, inclusive - But the second operand, (the number being subtracted from the top number) should be less than or equal to the first operand This ensures that the answers to subtraction problems are never negative how do we do this? please help?
Asked
Active
Viewed 456 times
1 Answers
0
I probably should not answer this, as you didn't put any effort into this question, but I'll outline what to do:
- Declare two
int
variables,i1
undi2
. - Set
i1
to random between 1 and 999 - Set
i2
to random between 1 andi1
This should read in C like
int x = rand() % 999 + 1;
int y = rand() % x + 1;
This should ensure both x
and y
are random numbers between 1 and 999 and y
is less or equal than x
.

Thorsten Dittmar
- 55,956
- 8
- 91
- 139
-
srand(time(NULL)); int x = rand() % 900 +1; int y = rand() % 900 +1; for (x; x<=y; x++) { int t = x; cout <
– mike Jun 14 '16 at 12:19 -
-
I can not do this Set i1 to random between 1 and 999 Set i2 to random between 1 and i1 – mike Jun 14 '16 at 12:20
-
int x = rand() % 900 +1; int y = rand() % 900 + 1; if(x>=y) { cout << "\n " << x <<"\n + " << y <<"\n -----" << endl ; } else { cout << "\n " << y <<"\n + " << x <<"\n -----" << endl ; – mike Jun 14 '16 at 12:36
-
You said both numbers should be random between 1 and 999, but the second should be smaller or equal to the first. This is what I'm saying: First operand `i1` is random between 1 and 999, the second is random between 1 and `i1`. I'll put this into the question. – Thorsten Dittmar Jun 14 '16 at 12:45
-