Basics in arrays, c++.

Jan 17, 2018 at 12:38pm
I'm a beginner in c++ and i have been given a project to do in c++. It may look easy to a person that has been doing this for a long time but I am still learning.

I have to create a two dimensional array[5][5] with random numbers from 0 to 20, i should first print the numbers in the array on the screen and then find the sum of all of them. Also i should use the srand function with #include <time.h>.
Can i have you guys' help. Thanks in advance!
Jan 17, 2018 at 1:10pm
Jan 17, 2018 at 1:17pm
Thank you for the link but how do i assign each number in the array to the srand function so each of the is random.
Jan 17, 2018 at 4:03pm
Just call rand() % 21; for each element in the array
Jan 17, 2018 at 7:35pm
I'll just drop this link in here as I see you're using a two dimensional array.

http://www.tutorialspoint.com/cplusplus/cpp_multi_dimensional_arrays.htm

Cheers!
Joe
Jan 17, 2018 at 7:51pm
Cheers for the replies guys! I just declare srand like srand(time(NULL)) and use the rand feature, all sorted for now!
Feb 4, 2018 at 1:30am
About random,
the srand() function will randomize the seed (seed-randomize). This operation will make the numbers generated by rand() more random.
When you're debugging, you may not want to call "srand()". Doing so will make every execution give you the exact same random numbers.
(so if you find some errors, without srand you can replicate the same situation, while with srand numbers will change and the error may not occur again)
Last edited on Feb 4, 2018 at 1:30am
Topic archived. No new replies allowed.