Modulus Operator Error

Here is my error:

120: error: no match for 'operator%' in '*((+(((unsigned int)i) * 8u)) + cards) % 13


It is in its beginning stages, but I am getting the above error, and am not sure why. I have included the math.h library and made sure that I am using the right symbol. Any suggestions?

Here is the code:

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

  #include <iostream>
  #include <fstream>
  #include <string>
  #include <math.h>
  #include <cstdlib>

  
  using namespace std;


  struct Hand {
      int cards;
      int numCards;
  };


  //declare functions

  void cardRank(Hand cards[], int[13]);


  int main()  { 


  string fileN;                     
  ifstream inf;
  Hand playing[52];
  int countCards;

  //arrays for card values/rank and card suit
  int Values[13];
  int types[4];

  readCards(inf, cards);

  inf.close();
  return 0;
  }


//*************************cardRank*******************************
//  Name:          cardRank
//  Description:   
//  Parameters:    ifstream& int, int cardValues[]
//  Return:        none
//****************************************************************
	void cardRank(Hand cards[], int cardValues[])  {
	
	int initVal = 0;    //initializes and traverses array cardValues
	int i = 0;         //initializes and traverses array of struct for card
	
	for (int rankCount = 0; rankCount < 13; rankCount++) {
	     int rank = cards[i] % 13;
	
		initVal++;
	} 

	}//function delimiter

Last edited on
The type of expression

cards[i]

is struct Hand. See its definition

struct Hand {
int cards;
int numCards;
};


As you see it has no overload operator %.

So this code

int rank = cards[i] % 13;

is invalid.
Last edited on
So because it is a struct I have to overload the operator? Just want to be sure I am understanding you.
There is no such operator as % applied to structures in C/C++. This operator is defined only for integer types.
OK. I guess I was thinking that because the array of struct is of integer type that it would allow it. Thank you for your help - will look up how best to accomplish doing modulus with structs.
Either of these would be valid:
int rank = cards[i].cards % 13;

int rank = cards[i].numCards % 13;

... maybe this is what was intended?

By the way, it does not seem a very good idea to call the array "cards" when that is also the name of one of the member variables of the struct.
By the way, it does not seem a very good idea to call the array "cards" when that is also the name of one of the member variables of the struct.


Yikes - thank you. Will change that first and then work on the rest.
Topic archived. No new replies allowed.