Help debugging pointer problems

Hello,
I am making the game Yahtzee as a school assignment.

Below is largely outline code, and bits an pieces that I'm working on.
My big problem is that I am handling pointers incorrectly it seems.
I'm not sure if it's my syntax, how I'm handling them, or both.

But I have illustrated in comments off to the side where I get errors. (-fpermissive to be specific)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#include <iostream>
#include <string>
#include <cmath>
#include <cstdlib>
#include <ctime>
 
using namespace std;


// catagory 13
void chance(int *dice_ar, int *p1_score){                                                              // <--#### -fpermissive
   int total = 0;
   for(int i=0;i<5;i++){
      total += dice_ar[i];
   }

   p1_score[13] = total;
   cout << endl << p1_score[13];

}


// catagories 1 - 6
void calc_num(int choice, int *dice_ar){                      						// <--#### -fpermissive
   int total = 0;

   for(int i=0;i<5;i++){
      if(dice_ar[i] == choice){
	 total += choice;
      }
   }

}
    




void diceroll(int *dice_ar){
   
   int choice;
   int x = 0;
   int n = 0;
   do{
   for(int i = 0; i < 5; i++){
      
      x = rand() % 6 + 1;
      dice_ar[i] = x; 

      cout << "Dice " << i+1 << " is " << x << endl;
      
       }
   ++n;

   cout << "To reroll all of your dice, enter 1." << endl << "To keep your dice, enter 2." << endl;  
   cin >> choice;                                           
   }while(choice == 1 && n < 3);
   
   
}

void catagories(int *dice_ar, int *p1_score){
   int choice = 0;

   
   //Display 13 Catagories
   cout << "\n 1-6) Catagories 1-6 are numeric collections of those numbers\n 7) Three of a kind \n 8) Four of a kind \n 9) Full House (two same & three same) \n 10) Small Straight (4 in a row)" << endl;
   cout << "11) Large Straight (5 in a row) \n 12) Yahtzee (Five of the same) \n 13) Chance (Sum of dice) \n" << endl;
   
   //Prompt User
   cout << "Select a catagory: ";
   cin >> choice;                                //    <----------------------------CIN NOT WORKING 
  
    if(choice > 0 && choice <= 6){
       calc_num(choice, *dice_ar);                                                                                    // <--#### -fpermissive
    }
    if(choice == 7)                                     // 7) (3 of a kind)
    if(choice == 8)   					    // 8) (4 of a kind)
       a_kind(*dice_ar, p1_score);                                                                                     // <--#### -fpermissive
    if(choice == 13){ 				    // 13) (chance)
       chance(*dice_ar, *p1_score);                                                                                  // <--#### -fpermissive
    }

}                                           


int main(){
   srand(time(NULL));
   int dice[5];
   int p1_score[16];
// int* P2_sheet = new int[size];       <--- P2 Must be dynamic

  diceroll(dice);     
  chance(dice, p1_score);
  catagories(dice, p1_score);

 // calculate_score(dice);

return 0;
}



Here is what the compiler tells me is wrong.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
  program5.cpp:92:33: error: invalid conversion from ‘int’ to ‘int*’ [-fpermissive]
        calc_num(choice, *dice_ar);                                                                                    // <--#### -fpermissive
                                 ^
program5.cpp:24:6: error:   initializing argument 2 of ‘void calc_num(int, int*)’ [-fpermissive]
 void calc_num(int choice, int *dice_ar){                            // <--#### -fpermissive
      ^
program5.cpp:96:33: error: ‘a_kind’ was not declared in this scope
        a_kind(*dice_ar, p1_score);                                                                                     // <--#### -fpermissive
                                 ^
program5.cpp:98:34: error: invalid conversion from ‘int’ to ‘int*’ [-fpermissive]
        chance(*dice_ar, *p1_score);                                                                                  // <--#### -fpermissive
                                  ^
program5.cpp:11:6: error:   initializing argument 1 of ‘void chance(int*, int*)’ [-fpermissive]
 void chance(int *dice_ar, int *p1_score){                                                              // <--#### -fpermissive
      ^
program5.cpp:98:34: error: invalid conversion from ‘int’ to ‘int*’ [-fpermissive]
        chance(*dice_ar, *p1_score);                                                                                  // <--#### -fpermissive
                                  ^
program5.cpp:11:6: error:   initializing argument 2 of ‘void chance(int*, int*)’ [-fpermissive]
 void chance(int *dice_ar, int *p1_score){                                                              // <--#### -fpermissive
      ^


Thank you so much to whomever is willing to look at this for me.

I hope that it is evident what I am trying to do with the pieces of code in regards to the pointers and variables that are in question.
The error is not "-fpermissive". That's a compiler flag that controls a set of diagnostics. It makes me wonder if you read all of the error messages or not. Some of them are pretty obvious. For instance, "'a_kind" was not declared in this scope", i.e., it doesn't know what a_kind is (you seem to think it's a function).

Another one of your errors is "invalid conversion from 'int' to 'int*'" So you are trying to assign an integer directly to a pointer. That's not a sensible thing to do. Remember that when you dereference a pointer (by putting an asterisk in front of it) you get the thing it points to. So *dice_ar is an int and you are passing it to a function parameter expecting a pointer-to-int. But wait, that's exactly what dice_ar is! So just pass it without the *.

You do the same thing in a couple of other places.
Last edited on
Thank you for your help.
I think that fundamentally the problem is that I don't understand pointers intimately.

Overlooking errors that I should really understand (like errors in scope) is most likely a result of me putting too many consecutive hours into this thing.

Thank you again. I know it's a bit of a scattered post.
This is helpful
Topic archived. No new replies allowed.