Chapter 2, page 54


#1

Hi All

My program works but I get a yellow warning lights on the last two lines below:

// get the index of a random adjective/noun from the lists
// Note: the % operator, called the modulo operator, gives
// you the remainder.  So the adjsectiveIndex is a random number
// from 0 to 2 inclusive

int adjectiveIndex = rand() % [randomAdjectiveList count];  // Semantic Issue: Implicit conversion loses integer precision: 'unsigned long' to 'int'

int nounIndex = rand() % [randomNounList count];  // Semantic Issue: Implicit conversion loses integer precision: 'unsigned long' to 'int'

Can anyone help how to fix this?

Thanks in advance
Diggerbyte


#2

I have the same issue now… Quick-and-dirty solution for it will be:

int adjectiveIndex = (int)(rand() % [randomAdjectiveList count]);
int nounIndex = (int)(rand() % [randomNounList count]);

Still, I bet there is more fundamental solution…


#3

I found another thread for this issue:

viewtopic.php?f=77&t=1743


#4

Thanks Makepo

I’ve decided I should read the whole forum by chapter before posting next time.

Diggerbyte