So i'm trying to figure out why this isn't working correctly and i keep getting a passing argument 1 of setText error. if anyone could please look at it i'm sure its something stupid.
Is num1 an int? userGuess.text or [userGuess setText: ] expects a string, not an int. You'll have to use stringWithFormat like you did when setting the text of guessOutput.
So they syntax seems to be right now but it keeps reverting to the last if statement, the only reason I make it display the random number at first is so I know what the value is so I can test it, and no matter if I guess right on, to low or to high it tells me to high.
and thank you so much for your help I was stumbling through this all day yesterday to get frustrated by the int value vs the string. he is what i have so far.
Also I just added a guessCount so it could count how many tries it takes by setting it to 0 in the awake from nib and then adding one to the int value everytime they hit the guess button. how would i get that to display with a string the you guessed right statement
Code:
#import "Controller.h"
@implementation Controller
- (void)awakeFromNib
{
srand ( time(NULL) );
randomNum = rand() % 100;
// This line will be taken out when I know my if statements work properly
guessOutput.text = [NSString stringWithFormat:@"%i", randomNum];
[userGuess becomeFirstResponder];
guessCount = 0;
}
- (IBAction)guess:(id)sender;
{
num1 = [userGuess.text intValue];
guessCount = guessCount + 1;
if (num1 == randomNum);
{
// I want to add the guess count after your guessed right
guessOutput.text = @"You Guessed Right";
}
if (num1 > randomNum);
{
guessOutput.text = @"Too Low";
}
if (num1 < randomNum);
{
guessOutput.text = @"Too High";
}
}
@end
Last edited by thavok; 02-10-2010 at 07:32 AM.
Reason: updating code
You've got semicolons after your if statements, they shouldn't be there. What's happening is that each of your if statements is controlling an empty statement created by that stray semicolon rather than the compound statement in braces you want it to control.
__________________
Visit Mr Jack Games for my blog and more about my games
Thank you again it works like a charm, sorry this is my first solo app, i've been going through some books but with only a background in assembly and basic objective c is taking a bit to learn.