int firstSlot = slot1.generateSlot(1);
int secondSlot = slot2.generateSlot(2);
int thirdSlot = slot3.generateSlot(3);
cout << "The first slot was " << slot1.m_slotpicture << endl;
cout << "The second slot was " << slot2.m_slotpicture << endl;
cout << "The third slot waas " << slot3.m_slotpicture << endl;
checkWinner(firstSlot, secondSlot, thirdSlot);
return 0;
}
I want to try making a slot machine game this time using objects but everytime I render I get the same number how would I do it that I get a different number everytime ?
Just to explain the previous post: '=' is assignment but, (in)conveniently also returns the assigned value which can then be converted to bool. '==' is comparison. You also don't want to return a reference in generateSlot - that variable is local to the loop, and goes out of scope at the end of the curly bracket. Its value needn't persist between iterations of the loop, nor after the function returns. In practice, it might seem to work for now, but it can, does, and will break.
You seem to use references in a lot of places you don't need to, actually. You might be trying to optimize, but for built-in types the difference is likely to be either none at all or negligible. You want to use const reference for that, anyway - non-const reference lets you directly modify the argument, which is poor documentation for anyone using or reading your code, apart from anything else. If you need a copy, just pass by value.
That for loop, though, is the real problem. Now that you've 'fixed' the condition to be '==', it will first set i to 0, then check if i and slotNumber are equal. If slotNumber is 0, it'll execute the first iteration of the loop and return immediately (i.e. without actually looping). If slotNumber isn't 0, the function will return without actually returning a value. Except that the calling code doesn't know this, so it'll look for the return value and take whatever garbage value it finds there. Since generateNumber returns a reference, this probably means it later tries to read from an address that it doesn't have access to, and crashes with an access violation or segmentation fault. (When you say 'it crashes', you need to give us more detail about how, and what information you get when it does so - but I'm assuming it's one of these two.)
I think you want to delete the for loop entirely, and remove the slotNumber parameter which seems completely superfluous. Removing srand will fix the 'same number every time' problem.