1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

about selection control

Discussion in 'C' started by pawan20, Nov 19, 2010.

  1. pawan20

    pawan20 New Member

    Joined:
    Nov 19, 2010
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    this code is not proper work.
    Code:
    #include<stdio.h>
    #include<conio.h>
    void main()
    {
    char n[10],c[10];
    clrscr();
    printf("enter ur name=");
    scanf("%s",n);
    printf("enter ur city name=");
    scanf("%s",c);
    
    if(c=="agra")
    printf("welcome");
    else
    printf("Bye-Bye");
    getch();
    }
     
    Last edited by a moderator: Nov 19, 2010
  2. jimblumberg

    jimblumberg New Member

    Joined:
    May 30, 2010
    Messages:
    120
    Likes Received:
    29
    Trophy Points:
    0
    First: Please use code tags!!!

    Second: What is wrong with the program?

    What exactly is wrong with it?

    Does it compile without warnings/errors?

    If not please post the exact error messages.

    What do you expect the program to do?

    What is it doing?

    What are you entering when you run the program?

    Jim
     
    shabbir likes this.
  3. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,285
    Likes Received:
    364
    Trophy Points:
    83
    Just Code Tags is not good but also indent your code properly to make it better readable.
     
  4. virxen

    virxen New Member

    Joined:
    Nov 24, 2009
    Messages:
    387
    Likes Received:
    90
    Trophy Points:
    0
    see the changes and comments

    Code:
    #include<stdio.h>
    #include<conio.h>//compiler specific
    #include<string.h>//add this library
    
    int main(){//error 1 never void main always int main()
        char n[10],c[10];
        clrscr();//compiler specific
        printf("enter your name=");
        scanf("%s",n);getchar();//always after a scanf
        printf("enter your city name=");
        scanf("%s",c);getchar();//always after a scanf
        if(strcmp(c,"agra")==0)//corect way to compare 2strings. ==0 means 2 strings are equal
            printf("welcome");
        else
            printf("Bye-Bye");
        getch();//compiler specific
    }
    
    
    compiler specific means that it does not work in all compilers but only in few of them
     
    shabbir likes this.

Share This Page