-4

im a 1st grader when it comes to c and need help with storing 5 random values in an array and outputting them. Heres where am at.

#include <stdio.h>
#include <time.h>
#include <stdlib.h>

struct score_card {int A_ones; int B_twos; int C_threes; int D_fours; int E_fives; int  F_sixes; int G_chance;};
int dice_rolls[5];
int randomize(void);

int value;

int main(void) {
struct score_card test;

randomize;
int i;
    for(i = 0; i <= 4; i++){
    printf("%d\n", dice_rolls[i]);
    }
printf("\n");
return 0;
}


int randomize(void){
int i;
srand(time(0));
for(i = 0; i <= 4; i++){
    value = rand() % 6 + 1;
    dice_rolls[i] = value;
  }
}

The output is : 6294304 6294308 6294312 6294316 6294320

the goal was to use modular division to get values from 1 -->6 and store them in the dicerolls array.

Fuadk1
  • 1
  • 1

1 Answers1

1

I see two immediate problems.

First. you're not terminating your random numbers with a newline. That's why they're all strung together in a big sequence. Change your output line to:

printf("%d\n", &dice_rolls[i]);

Secondly, you're not actually calling randomize. The correct way to call it is with:

randomize();

The statement randomize; is simply an expression giving you the address of the function. It's as useless in this case as the expression 42; which also does nothing. However it's valid C so the compiler doesn't necessarily complain.

paxdiablo
  • 854,327
  • 234
  • 1,573
  • 1,953
  • Thanks! Yes the \n was definitely giving me a runon output. As for randomize my mistake im dealing with putty which sometimes makes it difficult to spot my syntax errors. My output currently is 6294304 6294308 6294312 6294316 6294320 it seems like the modular division didnt work in giving me values less than 6. – Fuadk1 Dec 15 '13 at 23:39
  • @Fuadk1 You're printing `&dice_rolls[i]`, the *address* of `dice_rolls[i]` (that's what the `&` does) rather than the value. – David Schwartz Dec 16 '13 at 00:06