0

I need to create a string in Xcode that I can keep adding to every time a calculation is performed within a function.

if(answer != 0) answer1 = [NSString stringWithFormat:@"%d / %d = %d \n", answer, number[i], myans];

return 1;

I need the 'answer1' value to ammend itself after each true if statement. for example :-

first correct statement :-

answer1 now equals "10 / 5 = 2 \n"

second correct answer :-

answer1 now needs to equal "10 / 5 = 2 \n 200 / 10 = 20 \n"

and so on until the loop finishes.

The value of the string has to be available outside of the function.

1 Answer 1

1

You can try somthing like this

answer1 = [answer1 stringByAppendingFormat:@"%d / %d = %d \n", answer, number[i], myans];

Hope it will work...

Sign up to request clarification or add additional context in comments.

4 Comments

Great that seems to work with the calculation thanks.
The problem I have now is that I need to write the text to a UITextWindow from within the function.
So :- answer1 = [answer1 stringByAppendingFormat:@"A1 %d / %d = %d \n", answer, number[i], myans]; [self.TextWin setText:answer1];
@ user2862680: you can try to make a UILabel and set the answer1 to UILabel's text and add that UILabel to your view

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.