Here's the code. A simple use of a for loop.
The book I'm reading says that "for (int n = 1; n <= number; n++)" is a valid way of declaring and initializing a variable. There is also a footnote the says "This is a feature added to the 1999 ANSI C Standard (sometimes referred to ad C99). If you're using gcc and you get an error trying to use this feature, try adding the -std=c99 option to the command line."
I do get an error and I'm using gcc via Xcode. Is there a #import or something else that adds this feature to Xcode without having to use Terminal?
#import <stdio.h>
int main(int argc, char *argv[])
{
int triangularNumber = 0;int number = 0;
printf ("What triangular number do you want to calculate: ");scanf ("%i", &number);
for (int n = 1; n <= number; n++)triangularNumber += n;printf ("Triangle number %i is %i\n", number,triangularNumber);
return 0;}
The book I'm reading says that "for (int n = 1; n <= number; n++)" is a valid way of declaring and initializing a variable. There is also a footnote the says "This is a feature added to the 1999 ANSI C Standard (sometimes referred to ad C99). If you're using gcc and you get an error trying to use this feature, try adding the -std=c99 option to the command line."
I do get an error and I'm using gcc via Xcode. Is there a #import or something else that adds this feature to Xcode without having to use Terminal?