I am learning about the 'arrays' in my book right now. To better understand it I wrote my own test code but I am having a problem. I know this goes back to pointers and variable addresses in memory. Using a function, I am trying to add the total of the dice rolls and return that value to the 'hold' variable. Here is the code.
I would be thankful for any help in understanding.
Thanks.
Code:
#include <stdio.h>
#include <time.h>
#include <stdlib.h>
int dice (void);
int total (int rollNum, int *newValue);
int main (int argc, const char * argv[]) {
srand(clock()); // seed for random num gen
int rolls [13], i, hold; // create my variables
hold = 0;
for (i=0; i<=12; i++) // loop till all the rolls have a number
rolls[i] = dice(); // put a random number into each array var
i = 0; // I rest the counter to 0
for (i=0; i<=12; i++) // This loop adds all the dice rolls and adds the value to hold
total (rolls[i], &hold);
i = 0; // I rest the counter to 0
for (i=0; i<=12; i++) // loop that displays each dice roll
printf("Array #[%d] hold a %d value\n\n", i, rolls[i]);
printf("the total added amount is %d", hold); // prints total of dice rolls
return 0;
}
int dice (void) { // Rolls a random 6 sided die
return (rand() % 6) + 1;
}
int total (int rollNum, int *newValue){
&hold = rollNum + *newValue;
}
I would be thankful for any help in understanding.
Thanks.