c# - Display random number and sorting -
i hitting wall here, fellow people. there way can generate random numbers, , indicate them if positive or negative?
i tried using if
statement, know once hits if
doesn't go else
.
please keep code simple in such way person understand what's going on or @ least indicate what's going on in code.
how can fix mistake?
random rnd = new random(); console.writeline("\n5 random integers -100 100:"); (int x = 1; x <= 5; x++) { if (x >= 0) { console.writeline("these positive numbers: {0}", rnd.next(0, 100)); } else { console.writeline("these negative numbers: {0}", rnd.next(-100, 0)); } } console.readline();
try following code... don't compare x; have compare random number.
random rnd = new random(); console.writeline("\n5 random integers -100 100:"); (int x = 1; x <= 5; x++) { int y = rnd.next(-100, 100); if (y >= 0) { console.writeline("these positive numbers: {0}", y.tostring()); } else { console.writeline("these negative numbers: {0}", y.tostring()); } } console.readline();
Comments
Post a Comment