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

Programming C first time

Discussion in 'C' started by gelampropo, Oct 12, 2011.

  1. gelampropo

    gelampropo New Member

    Joined:
    Oct 12, 2011
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    0
    Guys i need your help.

    I want to make code about this :


    printf("MAIN MENU\n");

    printf("[d] Display Empty Chess Board\n");

    printf("[v] Check Validity of Chess Notation\n");

    printf(" Save Moves to a Text File\n");

    printf("[f] Find Chess Moves in a String\n");

    printf("[e] End Program\n");

    If the user select one of the correct characters (d,v,s,f) the programm is being executed.
    If the user select e, the programm will be terminated
     
  2. ophelia.2010

    ophelia.2010 New Member

    Joined:
    Oct 18, 2011
    Messages:
    14
    Likes Received:
    0
    Trophy Points:
    0
    Occupation:
    student
    Location:
    london
    Create a new variable of character data type say choice and switch it, like

    printf("...............all the above content of yours)
    scanf("Enter the choice %c",&choice);
    switch(choice)
    {
    case 'd': Your program code
    case 'v': Your program code
    case 's': Your program code
    case 'f': Your program code
    case 'e':break;
    }

    This should work!!!
     
  3. gpk kishore

    gpk kishore New Member

    Joined:
    Jun 30, 2011
    Messages:
    82
    Likes Received:
    0
    Trophy Points:
    0
    Your code was correct but you should write it as
    switch(choice)
    {
    case 'd': Your program code
    break;
    //here you should use break statement otherwise if user give input as 'd' then all the code present under 'v','s','f','e' will also execute
    so better to use break statement after each case in your switch
     
  4. gelampropo

    gelampropo New Member

    Joined:
    Oct 12, 2011
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    0
    have you any idea about showing a chess. What about the following?

    Code:
    switch(select)
          {
             case 'd':                             /* if you choose d*/ 
                for(i=8;i>0;i--)
                {
                printf("%d %c %c %c %c \n",i,219,219,219,219);   
                }
                printf(" abcdefgh\n");
                system(“pause”); 
                }
                break;
     

Share This Page