Note that there are some explanatory texts on larger screens.

plurals
  1. POIf-statement won't work
    primarykey
    data
    text
    <p>I am trying to make an iOS-app, where the user answer some questions. The user gets a question, and he is going to range himself on a scale from 1 to 5. When the user have answered 30 questions, a new view will appear, where the user can see how many points he made, and a result-text based on the points.</p> <p>My problem is, when I use the if-else statement, I always get the result-text for the lowest sum.</p> <pre><code>int intSum = [self.sumFromList intValue]; if (intSum &gt;= 135) { NSLog(@"135"); } else if ((intSum &gt;= 120) &amp;&amp; (intSum &lt;= 134)) { NSLog(@"120 - 134"); } else if ((intSum &gt;= 105) &amp;&amp; (intSum &lt;= 119)) { NSLog(@"105 - 119"); } else if ((intSum &gt;= 90) &amp;&amp; (intSum &lt;= 104)) { NSLog(@"90 - 104"); } else if (intSum &lt;= 89) { NSLog(@"89 or less"); } else { NSLog(@"Error"); } </code></pre> <p>Can anyone see what I write wrong, or do anyone knows about any other functions to use? Instead of NSLog I have made two arrays witch generate a result- and range-text (<code>[self.result objectAtIndex:0];</code>. Of course the <code>0</code> will be changed based on the sum), and different text-colors.</p> <p>EDIT: This is how I calculate the points: If the user choose two points:</p> <pre><code>- (IBAction)twoPointsButton:(id)sender { [self addPointsToList:2]; } - (void)addPointsToList:(NSInteger)points { questionID = questionID + 1; // Used to get the question from array questionNo = questionNo + 1; // Used to get question number in title listPoints = listPoints + points; // Calculate the points if (questionID == numberOfQuestions) { ResultView *resultView = [[ResultView alloc] initWithNibName:@"ResultView" bundle:nil]; resultView.sumFromList = [NSString stringWithFormat:@"Sum: %i",listPoints]; questionID = 0; questionNo = 1; listPoints = 0; self.title = [NSString stringWithFormat:@"Spørsmål %i/%i",questionNo,numberOfQuestions]; self.question.text = [questions objectAtIndex:questionID]; [self presentViewController:resultView animated:YES completion:nil]; } else { self.question.text = [questions objectAtIndex:questionID]; NSString *newTitle = [NSString stringWithFormat:@"Spørsmål %i/%i",questionNo,numberOfQuestions]; self.title = newTitle; } </code></pre> <p>}</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload