Jan 15, 2013 at 6:51pm UTC
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 Jan 28, 2013 at 8:14pm UTC
Jan 15, 2013 at 6:59pm UTC
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 Jan 15, 2013 at 7:01pm UTC
Jan 15, 2013 at 7:18pm UTC
So because it is a struct I have to overload the operator? Just want to be sure I am understanding you.
Jan 15, 2013 at 7:21pm UTC
There is no such operator as % applied to structures in C/C++. This operator is defined only for integer types.
Jan 15, 2013 at 7:24pm UTC
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.
Jan 15, 2013 at 7:34pm UTC
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.