0

I need to have the bowl functions pass b1 and b2 into turntotal to add the two together in a different function. Here is the code, what am I doing wrong?

void bowl(){
    int b1=rand()%11;
    int b2=rand()%(11-(b1));
    int turntotal(&b1,&b2);
}

int turntotal(int *b1, int *b2){
    int bowltotal;
    bowltotal=((b1)+(b2));
    return(bowltotal);
}
mpiatek
  • 1,313
  • 15
  • 16
user7176564
  • 1
  • 1
  • 2
  • 2
    There is a good list of books [here](http://stackoverflow.com/questions/388242/the-definitive-c-book-guide-and-list), and it looks like you need one. – molbdnilo Mar 03 '17 at 16:45

1 Answers1

0

You need to dereference a pointer to get value from the address it points to so you would write:

int turntotal(int *b1, int *b2) {
     return (*b1) + (*b2);
}

However your function doesn't modify any of its parameters so you can simply write:

int turntotal(int b1, int b2) {
     return b1 + b2;
}

Also line:

int turntotal(&b1,&b2);

doesn't make sense. You probably want to assign value returned from that function to a new variable so you can write:

int sum = turntotal(&b1,&b2);

or

int sum = turntotal(b1,b2);

if you don't use pointers where you don't have to.

As suggested in the comments - this is some basic stuff and you should consider changing your learning resources to one of the good books.

Community
  • 1
  • 1
mpiatek
  • 1,313
  • 15
  • 16