I am trying to make an app that takes away or adds 1 to an integer if the text entered in a text field matches an object in an array.
The Code in my .m file
NSString *inputtwo =EnterNameText.text;
BOOL isItright = NO;
for(NSString *possible in scoreArray1)
{
if([inputtwo isEqual:possible] )
{
isItright = YES;
break;
}
}
NSString *wronginput = EnterNameText.text;
BOOL isWrong = NO;
for(NSString *wrong in scoreArray1)
{
if(![wronginput isEqual:wrong ] )
{
isWrong = YES;
break;
}
}
static int myInt;
if(isItright)
{
myInt++;
NSString *score = [NSString stringWithFormat:@"%d", myInt];
[scorelabel setText:score];
}
if (isWrong)
{
myInt--;
NSString *score = [NSString stringWithFormat:@"%d", myInt];
[scorelabel setText:score];
}
So the program checks if there is a match in the array called scoreArray1, if there is it will add 1 to myInt, if not it will take one away.
The problem is it is only taking one away regardless whether it is right or wrong.
Thanks for your time.