Thread: else if statement with example

  1. #16
    Banned
    Join Date
    Aug 2017
    Posts
    861
    Quote Originally Posted by jimblumberg View Post
    The problem is that in C90 all variable declarations must be prior to any executable code, you have variables declared in the middle of a block of code. Also line comments are not allowed in C90, you would need to use normal C comments /* comment */.

    And while int main(void) is the preferred way of defining a main that takes no arguments, omitting the void will usually not be an issue for main().
    I kind of figured it might be the way I declared my int and yes that is c++ comments, I do not pay much attention to that it is my preferred way I leave the other to /* block comment out my code. */ for the most part, but hopefully he will read this and do one of two things update his compiler or make the needed adjustments to the code. It's not like he cannot edit it . it is just a learning process.
    Last edited by userxbw; 12-01-2017 at 02:30 PM.

  2. #17
    Registered User
    Join Date
    May 2010
    Posts
    4,632
    it is just a learning process.
    Yes it is, I hope you learned something as well.

  3. #18
    Registered User
    Join Date
    May 2012
    Location
    Arizona, USA
    Posts
    948
    C99 is old enough to have graduated from high school, and it (if not C11) should be considered the default standard in use nowadays.

    The OP hasn't indicated that this is the problem, only that "I am getting error", which is very much not helpful. My guess is that they copied the syntax-highlighted code with its non-breaking spaces and got a bunch of "error: stray '\240' in program" messages or somesuch.

  4. #19
    Banned
    Join Date
    Aug 2017
    Posts
    861
    Quote Originally Posted by jimblumberg View Post
    Yes it is, I hope you learned something as well.
    yeah people really need to get updated to c99 or greater.

  5. #20
    Registered User
    Join Date
    May 2010
    Posts
    4,632
    C99 is old enough to have graduated from high school, and it (if not C11) should be considered the default standard in use nowadays.
    I agree, however since Turbo-C is still in wide use you can never take it for granted that the posters will be using modern C (but one can hope, I guess). Even gcc prior version 5 defaults to -gnu-90 and many people are still using these outdated versions of this compiler without altering the default settings.

    yeah people really need to get updated to c99 or greater.
    IMO, C11 should be the target, C99 is also fairly dated.

  6. #21
    Banned
    Join Date
    Aug 2017
    Posts
    861
    Quote Originally Posted by jimblumberg View Post
    I agree, however since Turbo-C is still in wide use you can never take it for granted that the posters will be using modern C (but one can hope, I guess). Even gcc prior version 5 defaults to -gnu-90 and many people are still using these outdated versions of this compiler without altering the default settings.
    on that note, then the posters need to embrace the ability to be able to modify the code they copy to get it work in their programs. I do, so I'll stay with that responsibility is theirs and not mine.

    Quote Originally Posted by jimblumberg View Post
    IMO, C11 should be the target, C99 is also fairly dated.
    of course. Can't really convey sarcasm in a post.

  7. #22
    Registered User
    Join Date
    May 2010
    Posts
    4,632
    on that note, then the posters need to embrace the ability to be able to modify the code they copy to get it work in their programs. I do, so I'll stay with that responsibility is theirs and not mine.
    This is where we will probably need to agree to disagree. You're the one posing as the expert, so you should be explaining what compiler options your code requires since the OP probably doesn't even know there is more than one standard, much less multiples.

  8. #23
    Banned
    Join Date
    Aug 2017
    Posts
    861
    Quote Originally Posted by jimblumberg View Post
    This is where we will probably need to agree to disagree. You're the one posing as the expert, so you should be explaining what compiler options your code requires since the OP probably doesn't even know there is more than one standard, much less multiples.
    I am not using any options it can compile using just gcc programName.c gets a.out I have not ran into anything in here that need extra options to compile. except when one is actually using the math header, then they've already ran their code, I am the one that needs to add -lm

    I already asked OP what the errors was then you chimed in before the OP posted back. So I was not even given time to address his issues.

    Still they ( OP - other people) need to learn how to modify their code to meet the requirements of their compiler, that is something they need to learn, not for me to ask if their compiler is up to date , to be sure it is not 6 years old, then post code that works on theirs.

    It is still their responsibility to learn how to work through errors to get code to work on their end. If I can learn how do it without any schooling ( which sounds so cheesy) then they too can learn how to.

    just like the code found online here and their that is written void main() just change it to int main then run it.
    just like when an OP post scanf_s and I have to change their code to get it to run on my compiler so i can work on it to help them out with it.
    this is code help not compiler help for another thing. I am not going to take myself to school to lean something that is outdated.
    Their are plenty of free compilers on line that meet the C99 or higher requirements. and as the other stated it probably is just a copy paste error.
    expert not, someone that might know a little more then them about what they are working on .maybe even knows what to do (and or) how to figure it out so I can show them, or try to lean them into it, even try to show them how to figure it out. OK.



    Code:
    userx@slackwhere:~/bin
    $ gcc ./student_grades.c
    userx@slackwhere:~/bin
    $ ls a.out
    a.out
    to each his own. you teach what you know, and I'll try to teach what I know.
    Last edited by userxbw; 12-01-2017 at 05:24 PM.

  9. #24
    Registered User
    Join Date
    Apr 2012
    Posts
    99
    This was the error
    Code:
    hello.c: In function 'main':
    hello.c:5:1: error: stray '\302' in program
     A A A A A 
     ^
    hello.c:5:2: error: stray '\240' in program
     A A A A A 
      ^
    hello.c:5:3: error: stray '\302' in program
     A A A A A 
       ^
    hello.c:5:4: error: stray '\240' in program
     A A A A A 
        ^
    hello.c:5:5: error: stray '\302' in program
     A A A A A 
         ^
    hello.c:5:6: error: stray '\240' in program
     A A A A A 
          ^
    hello.c:5:7: error: stray '\302' in program
     A A A A A 
           ^
    hello.c:5:8: error: stray '\240' in program
     A A A A A 
            ^
    hello.c:5:9: error: stray '\302' in program
     A A A A A 
             ^
    hello.c:5:10: error: stray '\240' in program
     A A A A A 
              ^
    hello.c:6:1: error: stray '\302' in program
     A A A A printf("Enter score\n");
     ^
    hello.c:6:2: error: stray '\240' in program
     A A A A printf("Enter score\n");
      ^
    hello.c:6:3: error: stray '\302' in program
     A A A A printf("Enter score\n");
       ^
    hello.c:6:4: error: stray '\240' in program
     A A A A printf("Enter score\n");
        ^
    hello.c:6:5: error: stray '\302' in program
     A A A A printf("Enter score\n");
         ^
    hello.c:6:6: error: stray '\240' in program
     A A A A printf("Enter score\n");
          ^
    hello.c:6:7: error: stray '\302' in program
     A A A A printf("Enter score\n");
           ^
    hello.c:6:8: error: stray '\240' in program
     A A A A printf("Enter score\n");
            ^
    hello.c:7:1: error: stray '\302' in program
     A A A A int score = 0;
     ^
    hello.c:7:2: error: stray '\240' in program
     A A A A int score = 0;
      ^
    hello.c:7:3: error: stray '\302' in program
     A A A A int score = 0;
       ^
    hello.c:7:4: error: stray '\240' in program
     A A A A int score = 0;
        ^
    hello.c:7:5: error: stray '\302' in program
     A A A A int score = 0;
         ^
    hello.c:7:6: error: stray '\240' in program
     A A A A int score = 0;
          ^
    hello.c:7:7: error: stray '\302' in program
     A A A A int score = 0;
           ^
    hello.c:7:8: error: stray '\240' in program
     A A A A int score = 0;
            ^
    hello.c:8:1: error: stray '\302' in program
     A A A A scanf(" %d", &score);
     ^
    hello.c:8:2: error: stray '\240' in program
     A A A A scanf(" %d", &score);
      ^
    hello.c:8:3: error: stray '\302' in program
     A A A A scanf(" %d", &score);
       ^
    hello.c:8:4: error: stray '\240' in program
     A A A A scanf(" %d", &score);
        ^
    hello.c:8:5: error: stray '\302' in program
     A A A A scanf(" %d", &score);
         ^
    hello.c:8:6: error: stray '\240' in program
     A A A A scanf(" %d", &score);
          ^
    hello.c:8:7: error: stray '\302' in program
     A A A A scanf(" %d", &score);
           ^
    hello.c:8:8: error: stray '\240' in program
     A A A A scanf(" %d", &score);
            ^
    hello.c:9:1: error: stray '\302' in program
     A 
     ^
    hello.c:9:2: error: stray '\240' in program
     A 
      ^
    hello.c:10:1: error: stray '\302' in program
     A A A A // applying process of elimination
     ^
    hello.c:10:2: error: stray '\240' in program
     A A A A // applying process of elimination
      ^
    hello.c:10:3: error: stray '\302' in program
     A A A A // applying process of elimination
       ^
    hello.c:10:4: error: stray '\240' in program
     A A A A // applying process of elimination
        ^
    hello.c:10:5: error: stray '\302' in program
     A A A A // applying process of elimination
         ^
    hello.c:10:6: error: stray '\240' in program
     A A A A // applying process of elimination
          ^
    hello.c:10:7: error: stray '\302' in program
     A A A A // applying process of elimination
           ^
    hello.c:10:8: error: stray '\240' in program
     A A A A // applying process of elimination
            ^
    hello.c:11:1: error: stray '\302' in program
     A 
     ^
    hello.c:11:2: error: stray '\240' in program
     A 
      ^
    hello.c:12:1: error: stray '\302' in program
     A A A A if(score > = 70)
     ^
    hello.c:12:2: error: stray '\240' in program
     A A A A if(score > = 70)
      ^
    hello.c:12:3: error: stray '\302' in program
     A A A A if(score > = 70)
       ^
    hello.c:12:4: error: stray '\240' in program
     A A A A if(score > = 70)
        ^
    hello.c:12:5: error: stray '\302' in program
     A A A A if(score > = 70)
         ^
    hello.c:12:6: error: stray '\240' in program
     A A A A if(score > = 70)
          ^
    hello.c:12:7: error: stray '\302' in program
     A A A A if(score > = 70)
           ^
    hello.c:12:8: error: stray '\240' in program
     A A A A if(score > = 70)
            ^
    hello.c:12:20: error: expected expression before '=' token
     A A A A if(score > = 70)
                        ^
    hello.c:14:1: error: stray '\302' in program
     A A A A A A A A printf("Good\n");
     ^
    hello.c:14:2: error: stray '\240' in program
     A A A A A A A A printf("Good\n");
      ^
    hello.c:14:3: error: stray '\302' in program
     A A A A A A A A printf("Good\n");
       ^
    hello.c:14:4: error: stray '\240' in program
     A A A A A A A A printf("Good\n");
        ^
    hello.c:14:5: error: stray '\302' in program
     A A A A A A A A printf("Good\n");
         ^
    hello.c:14:6: error: stray '\240' in program
     A A A A A A A A printf("Good\n");
          ^
    hello.c:14:7: error: stray '\302' in program
     A A A A A A A A printf("Good\n");
           ^
    hello.c:14:8: error: stray '\240' in program
     A A A A A A A A printf("Good\n");
            ^
    hello.c:14:9: error: stray '\302' in program
     A A A A A A A A printf("Good\n");
             ^
    hello.c:14:10: error: stray '\240' in program
     A A A A A A A A printf("Good\n");
              ^
    hello.c:14:11: error: stray '\302' in program
     A A A A A A A A printf("Good\n");
               ^
    hello.c:14:12: error: stray '\240' in program
     A A A A A A A A printf("Good\n");
                ^
    hello.c:14:13: error: stray '\302' in program
     A A A A A A A A printf("Good\n");
                 ^
    hello.c:14:14: error: stray '\240' in program
     A A A A A A A A printf("Good\n");
                  ^
    hello.c:14:15: error: stray '\302' in program
     A A A A A A A A printf("Good\n");
                   ^
    hello.c:14:16: error: stray '\240' in program
     A A A A A A A A printf("Good\n");
                    ^
    hello.c:17:1: error: stray '\302' in program
     A A A A else if (score > = 41)
     ^
    hello.c:17:2: error: stray '\240' in program
     A A A A else if (score > = 41)
      ^
    hello.c:17:3: error: stray '\302' in program
     A A A A else if (score > = 41)
       ^
    hello.c:17:4: error: stray '\240' in program
     A A A A else if (score > = 41)
        ^
    hello.c:17:5: error: stray '\302' in program
     A A A A else if (score > = 41)
         ^
    hello.c:17:6: error: stray '\240' in program
     A A A A else if (score > = 41)
          ^
    hello.c:17:7: error: stray '\302' in program
     A A A A else if (score > = 41)
           ^
    hello.c:17:8: error: stray '\240' in program
     A A A A else if (score > = 41)
            ^
    hello.c:17:26: error: expected expression before '=' token
     A A A A else if (score > = 41)
                              ^
    hello.c:19:1: error: stray '\302' in program
     A A A A A A A A printf("OK \n");
     ^
    hello.c:19:2: error: stray '\240' in program
     A A A A A A A A printf("OK \n");
      ^
    hello.c:19:3: error: stray '\302' in program
     A A A A A A A A printf("OK \n");
       ^
    hello.c:19:4: error: stray '\240' in program
     A A A A A A A A printf("OK \n");
        ^
    hello.c:19:5: error: stray '\302' in program
     A A A A A A A A printf("OK \n");
         ^
    hello.c:19:6: error: stray '\240' in program
     A A A A A A A A printf("OK \n");
          ^
    hello.c:19:7: error: stray '\302' in program
     A A A A A A A A printf("OK \n");
           ^
    hello.c:19:8: error: stray '\240' in program
     A A A A A A A A printf("OK \n");
            ^
    hello.c:19:9: error: stray '\302' in program
     A A A A A A A A printf("OK \n");
             ^
    hello.c:19:10: error: stray '\240' in program
     A A A A A A A A printf("OK \n");
              ^
    hello.c:19:11: error: stray '\302' in program
     A A A A A A A A printf("OK \n");
               ^
    hello.c:19:12: error: stray '\240' in program
     A A A A A A A A printf("OK \n");
                ^
    hello.c:19:13: error: stray '\302' in program
     A A A A A A A A printf("OK \n");
                 ^
    hello.c:19:14: error: stray '\240' in program
     A A A A A A A A printf("OK \n");
                  ^
    hello.c:19:15: error: stray '\302' in program
     A A A A A A A A printf("OK \n");
                   ^
    hello.c:19:16: error: stray '\240' in program
     A A A A A A A A printf("OK \n");
                    ^
    hello.c:22:1: error: stray '\302' in program
     A A A A else
     ^
    hello.c:22:2: error: stray '\240' in program
     A A A A else
      ^
    hello.c:22:3: error: stray '\302' in program
     A A A A else
       ^
    hello.c:22:4: error: stray '\240' in program
     A A A A else
        ^
    hello.c:22:5: error: stray '\302' in program
     A A A A else
         ^
    hello.c:22:6: error: stray '\240' in program
     A A A A else
          ^
    hello.c:22:7: error: stray '\302' in program
     A A A A else
           ^
    hello.c:22:8: error: stray '\240' in program
     A A A A else
            ^
    hello.c:24:1: error: stray '\302' in program
     A A A A A A A A printf("fail\n");
     ^
    hello.c:24:2: error: stray '\240' in program
     A A A A A A A A printf("fail\n");
      ^
    hello.c:24:3: error: stray '\302' in program
     A A A A A A A A printf("fail\n");
       ^
    hello.c:24:4: error: stray '\240' in program
     A A A A A A A A printf("fail\n");
        ^
    hello.c:24:5: error: stray '\302' in program
     A A A A A A A A printf("fail\n");
         ^
    hello.c:24:6: error: stray '\240' in program
     A A A A A A A A printf("fail\n");
          ^
    hello.c:24:7: error: stray '\302' in program
     A A A A A A A A printf("fail\n");
           ^
    hello.c:24:8: error: stray '\240' in program
     A A A A A A A A printf("fail\n");
            ^
    hello.c:24:9: error: stray '\302' in program
     A A A A A A A A printf("fail\n");
             ^
    hello.c:24:10: error: stray '\240' in program
     A A A A A A A A printf("fail\n");
              ^
    hello.c:24:11: error: stray '\302' in program
     A A A A A A A A printf("fail\n");
               ^
    hello.c:24:12: error: stray '\240' in program
     A A A A A A A A printf("fail\n");
                ^
    hello.c:24:13: error: stray '\302' in program
     A A A A A A A A printf("fail\n");
                 ^
    hello.c:24:14: error: stray '\240' in program
     A A A A A A A A printf("fail\n");
                  ^
    hello.c:24:15: error: stray '\302' in program
     A A A A A A A A printf("fail\n");
                   ^
    hello.c:24:16: error: stray '\240' in program
     A A A A A A A A printf("fail\n");
                    ^
    hello.c:25:1: error: stray '\302' in program
     A A A A A A A A A A A A A 
     ^
    hello.c:25:2: error: stray '\240' in program
     A A A A A A A A A A A A A 
      ^
    hello.c:25:3: error: stray '\302' in program
     A A A A A A A A A A A A A 
       ^
    hello.c:25:4: error: stray '\240' in program
     A A A A A A A A A A A A A 
        ^
    hello.c:25:5: error: stray '\302' in program
     A A A A A A A A A A A A A 
         ^
    hello.c:25:6: error: stray '\240' in program
     A A A A A A A A A A A A A 
          ^
    hello.c:25:7: error: stray '\302' in program
     A A A A A A A A A A A A A 
           ^
    hello.c:25:8: error: stray '\240' in program
     A A A A A A A A A A A A A 
            ^
    hello.c:25:9: error: stray '\302' in program
     A A A A A A A A A A A A A 
             ^
    hello.c:25:10: error: stray '\240' in program
     A A A A A A A A A A A A A 
              ^
    hello.c:25:11: error: stray '\302' in program
     A A A A A A A A A A A A A 
               ^
    hello.c:25:12: error: stray '\240' in program
     A A A A A A A A A A A A A 
                ^
    hello.c:25:13: error: stray '\302' in program
     A A A A A A A A A A A A A 
                 ^
    hello.c:25:14: error: stray '\240' in program
     A A A A A A A A A A A A A 
                  ^
    hello.c:25:15: error: stray '\302' in program
     A A A A A A A A A A A A A 
                   ^
    hello.c:25:16: error: stray '\240' in program
     A A A A A A A A A A A A A 
                    ^
    hello.c:25:17: error: stray '\302' in program
     A A A A A A A A A A A A A 
                     ^
    hello.c:25:18: error: stray '\240' in program
     A A A A A A A A A A A A A 
                      ^
    hello.c:25:19: error: stray '\302' in program
     A A A A A A A A A A A A A 
                       ^
    hello.c:25:20: error: stray '\240' in program
     A A A A A A A A A A A A A 
                        ^
    hello.c:25:21: error: stray '\302' in program
     A A A A A A A A A A A A A 
                         ^
    hello.c:25:22: error: stray '\240' in program
     A A A A A A A A A A A A A 
                          ^
    hello.c:25:23: error: stray '\302' in program
     A A A A A A A A A A A A A 
                           ^
    hello.c:25:24: error: stray '\240' in program
     A A A A A A A A A A A A A 
                            ^
    hello.c:25:25: error: stray '\302' in program
     A A A A A A A A A A A A A 
                             ^
    hello.c:25:26: error: stray '\240' in program
     A A A A A A A A A A A A A 
                              ^
    hello.c:27:10: error: stray '\302' in program
     return 0;A A A 
              ^
    hello.c:27:11: error: stray '\240' in program
     return 0;A A A 
               ^
    hello.c:27:12: error: stray '\302' in program
     return 0;A A A 
                ^
    hello.c:27:13: error: stray '\240' in program
     return 0;A A A 
                 ^
    hello.c:27:14: error: stray '\302' in program
     return 0;A A A 
                  ^
    hello.c:27:15: error: stray '\240' in program
     return 0;A A A

  10. #25
    Programming Wraith GReaper's Avatar
    Join Date
    Apr 2009
    Location
    Greece
    Posts
    2,738
    My goodness, all those strays! It seems your line spacings are totally messed up, you'll have to fix that... Try to pass the program through a source code formatter, it may fix it if you don't know how to remove them manually.
    Devoted my life to programming...

  11. #26
    Registered User
    Join Date
    Jun 2017
    Posts
    88
    My goodness, all those strays! It seems your line spacings are totally messed up, you'll have to fix that... Try to pass the program through a source code formatter, it may fix it if you don't know how to remove them manually.
    Are you saying that he has non-ASCII characters in his code? Is he somehow getting formatting characters or something in a copy-paste? I really have no idea what a stray error is. I've never gotten one to my knowledge.

  12. #27
    Programming Wraith GReaper's Avatar
    Join Date
    Apr 2009
    Location
    Greece
    Posts
    2,738
    Quote Originally Posted by jack jordan View Post
    Are you saying that he has non-ASCII characters in his code? Is he somehow getting formatting characters or something in a copy-paste?
    Yes, that's what I think happened here.
    Devoted my life to programming...

  13. #28
    Banned
    Join Date
    Aug 2017
    Posts
    861
    That has happened to me in here as well, from copy paste OP code to examine it further.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. 'If' Statement inside the Switch statement being ignored.
    By howardbc14 in forum C Programming
    Replies: 4
    Last Post: 04-11-2015, 11:45 AM
  2. Statement inside a statement.
    By JOZZY& Wakko in forum C Programming
    Replies: 15
    Last Post: 11-05-2009, 03:18 PM
  3. if statement
    By spencerhs5 in forum C Programming
    Replies: 3
    Last Post: 07-24-2006, 02:16 PM
  4. If Statement
    By boontune in forum C++ Programming
    Replies: 2
    Last Post: 09-17-2003, 07:56 AM
  5. if statement
    By ZakkWylde969 in forum C++ Programming
    Replies: 22
    Last Post: 07-11-2003, 10:48 PM

Tags for this Thread