I’m a beginner in Objective-C and also in the C language.
My code looks like:
- (IBAction)button:(id)sender {
int randomproces = rand() % 3;
switch (randomproces) {
case 0:
//do this
break;
case 1:
//do this
break;
case 2:
//do this
break;
default;
break;
}
}
Now I want to set something to another 3 buttons to make them correct or incorrect depending on a random situation.
- (IBAction)b1:(id)sender {
//if case 0 then set it correct
//else incorrect
}
- (IBAction)b2:(id)sender {
//if case 1 then set it correct
//else incorrect
}
// etc
How do I do this?
If I correctly understand your question, you want to do different things in the in the handlers for
b1,b2andb3depending on a random value selected in the handler forbutton?I that case the simplest is probably to make the random number variable in
buttonglobal, and use that in the other three button handlers: