1
#include<stdio.h>
int sumofDie(int value1, int value2);
int main( void ){
int die1[7];
int die2[7];
int i;
srand(time(NULL));
printf("Rolling die 1 ..........\n");
for( i = 0; i < 6; i++){
int value;
value = 1 + rand() % 6;
die1[i] = value;
}
printf("Rolling die 2......\n");
for ( i = 0; i < 6; i++){
int value;
value = 1 + rand() % 6;
die2[i] = value;
}
for( i = 0; i < 6; i++){
printf("The %d value of the array of the first die is: %d \n", i + 1, die1[i]);
if ( i == 6){
int k;
printf("\n");
for( k = 0; k < 6; k++){
printf("The %d value of the array of the second die is: %d\n", k + 1, die2[k]);
}
}
}
sumofDie(die1,die2);
return 0;
}
int sumofDie( value1, value2){
int sum = 0;
int i;
for( i = 0; i < 6; i++){
sum = value1[i] + value2[i];
if ( i == 6){
return sum;
}
}
}
I probably did it in a very long way, even though there was a simpler way to do it, but let’s go: I made this program to "capture" the random numbers of two dice on 6 sides and after thatlos... tried to use a function at the end to practice more what I’ve been learning so far but it turns out that when I try to compile, a mistake I still don’t know how to identify appears >> expected 'int' but argument is of type 'int *' I researched in some places and saw some people commenting on pointers, I haven’t gotten into this subject in C and, if that’s the case, how should I do this program so that I use smokes function to add up the final value?
What’s the line of error? Usually compilers point... or not ... for so long that I don’t touch C that I can’t even remember....
– mau humor
It’s not about programming, but given in English it’s Dice. Die is die. By the way, you’ve given at home?
– Antonio Alexandre
Detail: No problems, but you have 7 positions in your data, but only use 6.
– Antonio Alexandre
Is it not necessary to indicate the type of the vector? type int sumofDie(int *value1, int *value2) or int sumofDie(int value1[], int value2[]) or int sumofDie(int value1[7], int value2[7])
– TotallyUncool
in addition several of the warnings are also errors.
– JJoao