else is Miss Placeed????????

This is a discussion on else is Miss Placeed???????? within the C Programming forums, part of the General Programming Boards category; Here is my PGM and i mention the error alos.. please suggest the reason for the error so that i ...

  1. #1
    Registered User
    Join Date
    Apr 2006
    Posts
    83

    else is Miss Placeed????????

    Here is my PGM and i mention the error alos.. please suggest the reason for the error so that i will not repeat it...


    Code:
    #include <stdio.h>
    #include <stdlib.h>
    #include <conio.h>
    #include <ctype.h>
    int main()
    {
    char h,sex,c;  /* Health , Sex and City */
    int age;
    
    printf(" Health Stat -- Excellent=E or Poor=P, Sex-- M , F City -- City=C or V=village and age");
    scanf("%c %c %c %d",&h,&sex,&c,&age);
    clrscr();
    /* Condition 1st */
    
    if((h=='E' && sex=='M') &&( c='C')&&( age>=25 && age<=35));
           printf(" Premium is Rs 4 / Thousand and Policy amount can not exceed 2 lakhs");
    
    /*Condition 2nd */
    if((h=='E' && sex=='F') &&( c='C')&&( age>=25 && age<=35));
    printf("The Premium is 3/thousand and policy can not exceed Rs.1 lakh");
    
    /*3rd condition*/
    if((h=='P' && sex=='M') &&( c='V')&&( age>=25 && age<=35));
    printf(" Premium is 6/thosuand and policy can not exceed Rs.10000");
    
    /* Condition 4th*/
        else /*  Misplace else in fuciton main ()*/
        {
        printf("person is not insured");
        }
    
    
    getch();
    }

  2. #2
    Registered User
    Join Date
    Apr 2006
    Posts
    83
    Code:
    /* Condition 4th*/
        else /*  Misplace else in fuciton main ()*/
        {
        printf("person is not insured");
        }
    I also removed ' }' and '{' but the ssame problem.

  3. #3
    Banned
    Join Date
    Nov 2007
    Posts
    678
    There is also a book named Let Us C Solutions By Yaswant Kanetkar
    It not only solves the exercises from Let Us C, but also explains them very well.

  4. #4
    Registered User
    Join Date
    Jan 2008
    Posts
    287
    You definitely need to review the syntax for an if statement.
    Code:
    if (condition)
       single_statement;
    
    if (condition)
       single_statement;
    else
       single_statement;
    
    if (condition) {
      many_statements;
    }
    
    if (condition) {
       many_statements;
    }
    else {
      many_statements;
    }
    
    etc...
    There are no semicolons after the if (condition); <--- NOOOO, unless you want an empty statement here, which you almost NEVER want.

  5. #5
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Posts
    23,013
    I also recommend you learn indentation, because this is not very good at all,
    http://cpwiki.sf.net/User:Elysia/Indentation
    It's important because it will help you catch bugs, as well as make others be able to read it.
    Plus int main() should be int main(void) in C.
    And you should probably up warnings to max if you can. Some compiler will warn about empty if statements.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  6. #6
    Registered User
    Join Date
    Apr 2006
    Posts
    83

    Thumbs up

    Quote Originally Posted by manav View Post
    There is also a book named Let Us C Solutions By Yaswant Kanetkar
    It not only solves the exercises from Let Us C, but also explains them very well.
    I m using that only......

  7. #7
    Registered User
    Join Date
    Apr 2006
    Posts
    83
    Quote Originally Posted by Elysia View Post
    I also recommend you learn indentation, because this is not very good at all,
    http://cpwiki.sf.net/User:Elysia/Indentation
    It's important because it will help you catch bugs, as well as make others be able to read it.
    Plus int main() should be int main(void) in C.
    And you should probably up warnings to max if you can. Some compiler will warn about empty if statements.


    I tried everything that i can do but still same problem ? Give some clue that i can over come this. If i will oncec get to know my mistake now then i can be careful next time.

  8. #8
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Posts
    23,013
    What problem?
    Did you remove the ; after the ifs?
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  9. #9
    uint64_t...think positive xuftugulus's Avatar
    Join Date
    Feb 2008
    Location
    Pacem
    Posts
    355
    Remove the ; after the ) on the lines that start with if(

  10. #10
    Registered User
    Join Date
    Apr 2006
    Posts
    83
    Quote Originally Posted by xuftugulus View Post
    Remove the ; after the ) on the lines that start with if(
    Superb Man!!!!!!!!!!!!!!!!! you are amazing!!!!!!!!!!!!!

    Just problem solved..... I m also a fool...Knowing that if , else do not use ';' i made this blunder...........


    Thanks man..... I m impressed the way you pointed out this...amazing..

  11. #11
    Registered User
    Join Date
    Apr 2006
    Posts
    83
    This forum and the members are amazing here..!!! Very Usefull!!!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. What did I miss about boosts sparse matrix library?
    By pheres in forum C++ Programming
    Replies: 4
    Last Post: 04-13-2008, 09:09 AM
  2. Nostalgy
    By Mario F. in forum A Brief History of Cprogramming.com
    Replies: 67
    Last Post: 07-08-2006, 07:08 PM
  3. I miss C
    By silk.odyssey in forum C++ Programming
    Replies: 5
    Last Post: 05-03-2004, 07:00 PM

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