Thread: HELP NEEDED!!! Error C2143

  1. #1
    Registered User
    Join Date
    Aug 2013
    Posts
    3

    Unhappy HELP NEEDED!!! Error C2143

    I am getting an error C2143 in line 300 and 1101 in for loops.Please someone help me to solve this error.
    << mod(bored with scrolling): snipped 1000 lines of unindented code - see attachment in next post >>

  2. #2
    Registered User
    Join Date
    Aug 2013
    Posts
    3
    the code file...
    Attached Files Attached Files

  3. #3
    Registered User hk_mp5kpdw's Avatar
    Join Date
    Jan 2002
    Location
    Northern Virginia/Washington DC Metropolitan Area
    Posts
    3,817
    Are you compiling your code as C instead of C++. I downloaded/compiled the code and got the same error when compiling as C but when I switched to C++ the error disappeared.


    The problem is the "int" declaration
    Code:
    for(int i = 0; i <= 6 - 1; i++){
    ...that would have to be brought out of the for-loop:
    Code:
    int i;
    
    ...
    
    for( i = 0; i <= 6 - 1; i++){
    for it to be compiled as C. C++ rules don't have a problem with the first one.

    After that, your code compiled with just a few warnings:
    1>STANDARED GA.c(628): warning C4305: 'initializing' : truncation from 'double' to 'float'
    1>STANDARED GA.c(629): warning C4305: 'initializing' : truncation from 'double' to 'float'
    1>STANDARED GA.c(630): warning C4305: 'initializing' : truncation from 'double' to 'float'
    Caused by the following lines:
    Code:
    float crossoverProbability = 0.85;
    float mutationProbability = 0.03;
    float tournamentProbability = 0.90;
    ...which you can avoid by suffixing the value with an "f" to indicate float instead of the default double.

    Code:
    float crossoverProbability = 0.85f;
    float mutationProbability = 0.03f;
    float tournamentProbability = 0.90f;
    "Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
    -Christopher Hitchens

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    37,537
    From the complete lack of indentation, and the weird line breaks in strange positions, I'm guessing you just copy/pasted it from somewhere, found it "doesn't work", and proceeded with due dispatch to dump it on a forum (or two) for someone else to fix.

    Moments after google, I found this
    http://publications.lib.chalmers.se/...ext/138247.pdf
    Page 63, Appendix G to be precise.

    > I am getting an error C2143
    That's a shame, try this
    Compiler Error C2143

    Try doing some work for yourself before running into a forum SCREAMING your head off and dumping 1000+ lines of someone else's code on us.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  5. #5
    Registered User
    Join Date
    Oct 2006
    Posts
    3,445
    the source of that error is the fact that microsoft refuses to support the C99 standard, or any subsequent revision. declaration of a variable inside the declaration of a for statement is only available in C99 or later.

    I recommend using GCC or another standard-compliant, modern C compiler.
    What can this strange device be?
    When I touch it, it gives forth a sound
    It's got wires that vibrate and give music
    What can this thing be that I found?

  6. #6
    Registered User
    Join Date
    Aug 2013
    Posts
    3
    thanks all for helping me.am just a beginner in c..salem appreciate your thought...

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Help needed to remove error
    By amalendu in forum C Programming
    Replies: 3
    Last Post: 10-07-2011, 01:13 PM
  2. error Help needed!
    By alionas in forum C Programming
    Replies: 2
    Last Post: 04-07-2011, 12:29 PM
  3. C2143 errors
    By stormi in forum C Programming
    Replies: 2
    Last Post: 11-14-2009, 11:32 AM
  4. error C2143: syntax error : missing ')' before ';'
    By steve1_rm in forum C Programming
    Replies: 4
    Last Post: 05-14-2008, 11:06 AM