error: invalid operands of types 'int()' and 'int' to binary 'operator%'

#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;

int main()
{
srand(time(0));
int numOfDice;
numOfDice =6;
int remove;
char rollAgain = 'y';
int dice[6];
while(rollAgain == 'y')
{
for(int k=0; k<numOfDice; k++)
{
dice[k] = rand%6+1;
}
for(int k=0; k<6; k++)
{
cout<<dice[k]<< " ";
}
int counter;
counter = 0;
for(int k=0; k<numOfDice; k++)
{
if(dice[k]=1)
{
counter++;
}
}
cout<< "Here are the count of 1s: "<<counter<<endl;
cout<< "How many do you want to remove: ";
cin>>remove;
numOfDice = numOfDice - remove;
cout<<" Do you want to roll again ? ";
cin>>rollAgain;
}

return 0;


im getting that error in line 25, i dont know why. which is dice[k] = rand%6+1;
Last edited on
rand is a function. If you want to call a function, you must use parenthesis.

Change it to this:
 
dice[k] = rand() % 6 + 1;  // <- () parenthesis are not just for show 
Thank you!
Topic archived. No new replies allowed.