If Else Statement Goes Error!!!

This is a discussion on If Else Statement Goes Error!!! within the C Programming forums, part of the General Programming Boards category; I had a problem my mingw32 compilerr cannot compile this c code, Code: int exp1=5; int exp2=-5; int x,y; int ...

  1. #1
    Registered User loserone+_+'s Avatar
    Join Date
    Dec 2012
    Location
    Indonesia
    Posts
    112

    Question If Else Statement Goes Error!!!

    I had a problem
    my mingw32 compilerr cannot compile this c code,
    Code:
    int exp1=5;
    int exp2=-5;
    int x,y;
    int main()
      {
      if(!(exp1>exp2&&exp2<exp1)) {//Condition False
      x=5;y=-5;
      }
      else {
      x=0;y=0;
      }
      if((!(exp1!=exp2))||exp1==exp2) {//Condition True
      x=1;y=1;
      }
      else {
      return x,y;
      }
      if((!(x==0&&y==0))||x==y) {//Condition True
      printf("Attack!");
      }
      else {
      printf("RUN!");
      }
      return EXIT_SUCCESS;
      } /*expected input first if statement false
        expected input second if statement true
        expected input third if statement true*/
    i am using global variables though,
    i didnt know where the code going wrong really
    i cant figured this, anyone can explain whats wrong thing to me?
    the error message was
    ISO C++ forbids comparison between pointer and integer [-fpermissive]

  2. #2
    Registered User
    Join Date
    Feb 2013
    Posts
    9
    I could be mistaken but perhaps the & symbol needs some space. Otherwise it'll consider it as an address... Might be wrong.
    So try:
    x==0 && y == 0, etc. instead of x==0&&y==0

    Oh, and since main() is an int, doesn't it have to return a number? So EXIT_SUCCESS needs to be an integer.

  3. #3
    SAMARAS std10093's Avatar
    Join Date
    Jan 2011
    Location
    Nice, France
    Posts
    2,675
    EXIT_SUCCESS is defined in stdlib.h , so it is ok.

    If you indent your code, you will find the bug for sure.

    You can not do that! You can return one "thing" only.
    Code:
    return x,y;
    Last edited by std10093; 02-13-2013 at 07:22 AM.
    Code - functions and small libraries I use


    It’s 2014 and I still use printf() for debugging.


    "Programs must be written for people to read, and only incidentally for machines to execute. " —Harold Abelson

  4. #4
    Registered User loserone+_+'s Avatar
    Join Date
    Dec 2012
    Location
    Indonesia
    Posts
    112
    no, int main() isnt as int for variables,
    EXIT_SUCCESS means that programs already finished without wrong,
    the hardway says that after the program finished it become to condition before the program started,
    return can be used it many ways,
    and
    Code:
    return EXIT_SUCCESS;
    same as,
    Code:
    return 0;
    and space didnt disturb the code,
    however thanks for replies even ur advantages didnt solve my problem

  5. #5
    Registered User
    Join Date
    Feb 2013
    Posts
    9
    Oh, didn't catch that XD

  6. #6
    Registered User loserone+_+'s Avatar
    Join Date
    Dec 2012
    Location
    Indonesia
    Posts
    112
    Quote Originally Posted by std10093
    You can not do that! You can return one "thing" only.
    really that i can return one thing only?
    hmmm, i already change that and compile again
    still had errors

  7. #7
    SAMARAS std10093's Avatar
    Join Date
    Jan 2011
    Location
    Nice, France
    Posts
    2,675
    Yes. Post your updated code and the errors you get please
    Code - functions and small libraries I use


    It’s 2014 and I still use printf() for debugging.


    "Programs must be written for people to read, and only incidentally for machines to execute. " —Harold Abelson

  8. #8
    Registered User
    Join Date
    Nov 2012
    Posts
    1,062
    Quote Originally Posted by loserone+_+ View Post
    I had a problem
    my mingw32 compilerr cannot compile this c code,
    ...
    the error message was
    ISO C++ forbids comparison between pointer and integer [-fpermissive]
    1. It helps if you print what line the error occured on. We can't see your terminal and we don't know which line numbers really correspond to your code.
    2. Use a C compiler to compile C code, and use a C++ compiler to compile C++ code.

  9. #9
    Registered User loserone+_+'s Avatar
    Join Date
    Dec 2012
    Location
    Indonesia
    Posts
    112
    sorry for the not detailed information about my wrong code
    ISO C++ forbids comparison between pointer and integer [-fpermissive]
    are on
    Code:
    if(!(exp1>exp2 && exp2<exp1))
    and
    Code:
    if((!(exp1!=exp2)) || exp1==exp2)
    yeahh i already changing the return thing std10093,
    but still had the same errors, no updated errors was found

  10. #10
    SAMARAS std10093's Avatar
    Join Date
    Jan 2011
    Location
    Nice, France
    Posts
    2,675
    You are using a reserved name! exp2 from math.h!!! Chane the name and report back.

    Code:
    linux05:/home/users/std10093>gcc -Wall px.c -o px
    px.c:4: warning: built-in function 'exp2' declared as non-function
    Code - functions and small libraries I use


    It’s 2014 and I still use printf() for debugging.


    "Programs must be written for people to read, and only incidentally for machines to execute. " —Harold Abelson

  11. #11
    Registered User
    Join Date
    Nov 2012
    Posts
    1,062
    If you had used a C compiler to compile your C code, you would see that error.

  12. #12
    SAMARAS std10093's Avatar
    Join Date
    Jan 2011
    Location
    Nice, France
    Posts
    2,675
    The guy above is correct.

    To be complete, you received this error, because math.h is a function name. So, what happen when you write exp2 without the brackets? A function pointer, thus the error you had
    Code:
    ISO C++ forbids comparison between pointer and integer [-fpermissive]
    Code - functions and small libraries I use


    It’s 2014 and I still use printf() for debugging.


    "Programs must be written for people to read, and only incidentally for machines to execute. " —Harold Abelson

  13. #13
    Registered User loserone+_+'s Avatar
    Join Date
    Dec 2012
    Location
    Indonesia
    Posts
    112
    PROBLEM SOLVED!
    ok, the program now can be compiled using my mingw32 compiler
    thanks a lot!!!
    by the way whats exp thing from defined include<math.h>, do u have any ideas to that thing?

  14. #14
    SAMARAS std10093's Avatar
    Join Date
    Jan 2011
    Location
    Nice, France
    Posts
    2,675
    Of course. exp2.

    Consider doing what the other guy said with the compiler.
    Code - functions and small libraries I use


    It’s 2014 and I still use printf() for debugging.


    "Programs must be written for people to read, and only incidentally for machines to execute. " —Harold Abelson

  15. #15
    Registered User loserone+_+'s Avatar
    Join Date
    Dec 2012
    Location
    Indonesia
    Posts
    112
    okay, btw thanks for all of you respons

Page 1 of 2 12 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. syntax error in my if statement
    By UCFuser in forum C Programming
    Replies: 13
    Last Post: 04-01-2011, 01:57 PM
  2. Error proofing my switch statement.
    By Shamino in forum C++ Programming
    Replies: 10
    Last Post: 01-04-2008, 03:38 PM
  3. Replies: 3
    Last Post: 10-02-2007, 09:12 PM
  4. error when compiling if statement
    By robasc in forum C Programming
    Replies: 2
    Last Post: 07-08-2005, 08:20 PM
  5. an if statement with error
    By Unregistered in forum C++ Programming
    Replies: 5
    Last Post: 04-22-2002, 03:52 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21