Random Number
I am trying to make an app that generates a random nuber between 0 and a chosen number. The idea is the user types a number into a text box and presses the generate button and a label is changed to the random number.
Here my code for the button press
-(IBAction)button1Press: (id) sender{
NSString *input;
int randomNumber;
input = targetNumber.text;
int Number = [input intValue];
randomNumber = (random() % Number) + 1;
choice.text =(@"%d", randomNumber); //Getting error here
}
targetNumber is defined in the .h file as a UITextField <--- Is this correct?
choice is defined in the .h file as a UILabel
I am gettin a warning on the last line saying "passing argument 1 of 'setText:' makes pointer from integer without a cast".
When i type a number into the text box and press generate, the app crashes.
any ideas why I am getting the warning?
example code appreciated as I am new to Objective C.
Thanks in advance
|