You don't know as of Chapter 5 about "if" statements, but that's what should be used instead of the while. Better yet, why not have the for loop count by 5 instead of by 1?
Cheers,
Steve
Hi Steve!
That's exactly what I was trying to do with this:
for (n = 5; n <= 50; n + 5) {
But that gave me a warning and an infinite loop where the
n + 5 wasn't being used. So my final code went like this:
// Program to calculate a table of every 5th triangular numbers
#import <Foundation/Foundation.h>
int main (int argc, const char * argv[])
{
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
int n, triangularNumber;
NSLog(@"TABLE OF TRIANGULAR NUMBERS");
NSLog(@" n n (n + 1) / 2");
NSLog(@" -- -------------");
triangularNumber = 0;
for (n = 5; n <= 50; n = (n + 5)) {
triangularNumber = n * (n + 1) / 2;
NSLog(@" %2i %i", n, triangularNumber);
}
[pool drain];
return 0;
}