| | |
compiling error wtf!?!?
![]() |
•
•
Join Date: Oct 2003
Posts: 4
Reputation:
Solved Threads: 0
why do i get this compiling error with the following code??
numbers.c: In function `main':
numbers.c:33: `for' loop initial declaration used outside C99 mode
numbers.c: In function `main':
numbers.c:33: `for' loop initial declaration used outside C99 mode
C Syntax (Toggle Plain Text)
int main() { int oneNumber =0; // hold the valid integer entered int countPositiveFactors =0; // accumulate a sum , so should be initialize to 0 int sumPositiveFactors =0; // accumulate a sum , so should be initialize to 0 int prodPositiveFactors = 1; // accumulate a product so should be initialize to 1 while (1) { printf("Enter an integer > 1 :"); scanf("%d", &oneNumber); if (oneNumber > 1) break; else printf("Error: Number should be > 1\n"); _flushall(); // to flush all streams e.g. stdin } printf("\n\nHere is a list of the positive factors of %d\n",oneNumber); for (int i=1;i<=oneNumber;i++) { if (oneNumber%i==0) // one factor found { countPositiveFactors++; // add 1 to count of positive factors printf("%d ",i); // print this factor sumPositiveFactors+=i; // add this factor e.g. i to the sum prodPositiveFactors*=i; // multiply this factor with the previous factors } } printf ("\n\nThe number of positive factors of %d is %d.\n",oneNumber, countPositiveFactors); printf ("The sum of the positive factors of %d is %d.\n",oneNumber, sumPositiveFactors); printf ("The product of the positive factors of %d is %d.\n",oneNumber, prodPositiveFactors); return 0; }
You're either using a C compiler or you're compiling under C mode in a C++ compiler. The problem is that you can't declare a variable in a for() under C.
Replace
with this:
And it should work.
Replace
C Syntax (Toggle Plain Text)
for (int i=1;i<=oneNumber;i++) { if (oneNumber%i==0) // one factor found { countPositiveFactors++; // add 1 to count of positive factors printf("%d ",i); // print this factor sumPositiveFactors+=i; // add this factor e.g. i to the sum prodPositiveFactors*=i; // multiply this factor with the previous factors } }
with this:
C Syntax (Toggle Plain Text)
int i ; for (i=1;i<=oneNumber;i++) { if (oneNumber%i==0) // one factor found { countPositiveFactors++; // add 1 to count of positive factors printf("%d ",i); // print this factor sumPositiveFactors+=i; // add this factor e.g. i to the sum prodPositiveFactors*=i; // multiply this factor with the previous factors } }
And it should work.
•
•
Join Date: Feb 2003
Posts: 129
Reputation:
Solved Threads: 1
•
•
•
•
Originally Posted by Dante Shamest
You're either using a C compiler or you're compiling under C mode in a C++ compiler. The problem is that you can't declare a variable in a for() under C.
![]() |
Similar Threads
- compiling error (C++)
- Please Help Compiling Error (Java)
- compiling error (C)
- Another "cannot find symbol" compiling error (Java)
- compiling error, tried debugging but no luck (C)
- Please help me out, need help (C)
Other Threads in the C Forum
- Previous Thread: struct error (!?)
- Next Thread: hm.. wiered..
| Thread Tools | Search this Thread |
#include * ansi array arrays asterisks binarysearch calculate centimeter changingto char character convert copyanyfile copyimagefile copypdffile creafecopyofanytypeoffileinc createprocess() database dynamic execv fflush fgets file floatingpointvalidation fork forloop function getlogicaldrivestrin givemetehcodez grade gtkwinlinux histogram homework i/o ide inches include infiniteloop input interest intmain() iso keyboard km license linked linkedlist linux list looping lowest matrix meter microsoft mysql number oddnumber open opendocumentformat openwebfoundation pdf pointer posix power probleminc process program programming pyramidusingturboccodes radix read recursion recv recvblocked research reversing scheduling segmentationfault send sequential single socket socketprogramming stack standard strchr string suggestions systemcall test threads turboc unix urboc user variable whythiscodecausesegmentationfault win32api windowsapi





