What has possibly gone Wrong? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 3

What has possibly gone Wrong?

Please see my code - What is Incorrect?? How?? Why??? for relevant details... Please Help...

28th Mar 2017, 9:19 AM
Kinshuk Vasisht
Kinshuk Vasisht - avatar
11 Answers
+ 12
rand()%upper returns a random number in 0 to (upper-1). You are adding low (25) to it thereby resulting in out of range numbers.
28th Mar 2017, 9:31 AM
Krishna Teja Yeluripati
Krishna Teja Yeluripati - avatar
+ 11
@Kinshuk : If range is 25-30, you have to use (25 + (rand()%5)). But you are using (25 + (rand()%30)).
28th Mar 2017, 9:41 AM
Krishna Teja Yeluripati
Krishna Teja Yeluripati - avatar
+ 7
@Luka ??? I had set the range to 25-30, as the format is : lower_limit+(rand()%upper_limit)
28th Mar 2017, 9:38 AM
Kinshuk Vasisht
Kinshuk Vasisht - avatar
+ 7
And Thank You , Luka
28th Mar 2017, 9:45 AM
Kinshuk Vasisht
Kinshuk Vasisht - avatar
+ 6
@Krishna Teja Yeluripati But sir, lower is added to get range of lower->upper-1? Its there in the c++ tutorial?!
28th Mar 2017, 9:41 AM
Kinshuk Vasisht
Kinshuk Vasisht - avatar
+ 6
So we have to mod rand() with the difference of upper and lower? They haven' explained this on the tutorial at least...
28th Mar 2017, 9:44 AM
Kinshuk Vasisht
Kinshuk Vasisht - avatar
+ 6
Thank You, Sir
28th Mar 2017, 9:44 AM
Kinshuk Vasisht
Kinshuk Vasisht - avatar
+ 6
Why haven't they explained much about limits? This is even wrong in the C++ Book i have and on a few sites...
28th Mar 2017, 9:47 AM
Kinshuk Vasisht
Kinshuk Vasisht - avatar
+ 6
Guess it will be better to use random()...
28th Mar 2017, 9:50 AM
Kinshuk Vasisht
Kinshuk Vasisht - avatar
+ 5
Please Help?!!!
28th Mar 2017, 10:19 AM
Kinshuk Vasisht
Kinshuk Vasisht - avatar
+ 3
You are the experts! You tell me what is going on! I am unable to see any error...
28th Mar 2017, 12:00 PM
Kinshuk Vasisht
Kinshuk Vasisht - avatar