Thread Closed

Help With Assigning An Array With rand()

 
Share Thread Thread Tools
Nov14-07, 01:56 PM   #1
 

Help With Assigning An Array With rand()


1. The problem statement, all variables and given/known data
I need to write a function that takes an int array and the size of the array as parameters, then finds the largest num in the array, returns this value and then sets the value to zero.
Then in the main part of the program, I need to create an int array of 20 nums, assign all 20 values a random value between 1 and 100, print the values of the array out, then run the function 10 times, print the total of all the numbers returned by the function, and print out the new contents of the array.

3. The attempt at a solution
This is what I have: http://cpp.tastethepaste.org/1721
My problem is that when I print out the array, all 20 values are 20, the total of all the numbers returned by the function is different every time tho. And after the fact, it prints out the 20 values again, which are all still 20. What am I doing wrong?
PhysOrg.com
PhysOrg
science news on PhysOrg.com

>> Ants and carnivorous plants conspire for mutualistic feeding
>> Forecast for Titan: Wild weather could be ahead
>> Researchers stitch defects into the world's thinnest semiconductor
Nov14-07, 02:03 PM   #2
 
Recognitions:
Homework Helper Homework Help
Science Advisor Science Advisor
In the last two loops you are using the loop index from the previous loop - so you are actually printing the same value.

As a tip always declare the loop index inside the loop;

for (int i=0;i<BLAH;i++) {
}

Then the compiler will warn you if you access it outside the loop.
Nov14-07, 02:58 PM   #3
 
Wow, dumb mistake :p. Thank you very much for taking the time to look at my code, I appreciate it. All is good now, thanks again!
Nov14-07, 05:21 PM   #4
 
Recognitions:
Homework Helper Homework Help
Science Advisor Science Advisor

Help With Assigning An Array With rand()


Been there - done that , only bigger and dumber !
Thread Closed
Thread Tools


Similar Threads for: Help With Assigning An Array With rand()
Thread Forum Replies
Help With A Program Using Rand() Engineering, Comp Sci, & Technology Homework 13
I need help in assigning R/S stereochemistyr Biology, Chemistry & Other Homework 1
converting from an array of function values to coordinate array of different length Programming & Comp Sci 3
Rand cam engine Mechanical Engineering 10
Assigning Quantum Numbers Introductory Physics Homework 1