Converting pseudo code into C

Discussion in 'C Programming' started by sHeZ123, Apr 28, 2009.

  1. sHeZ123

    sHeZ123

    Joined:
    Apr 28, 2009
    Messages:
    2
    Likes Received:
    0
    Hi all,

    I am a newb and need help. I am working on a project which involves writing a C code version of the following pseudo code description for a robot so it avoids objects.

    -----------------------------
    Do forever
    {
    Input left_feeler;
    Input right_feeler;
    if(( left_feeler == 0)&&(right_feeler == 0))
    {
    Go forward;
    }
    if(( left_feeler == 1)&&(right_feeler == 0))
    {
    Turn sharp right;
    }
    if(( left_feeler == 0)&&(right_feeler == 1))
    {
    Turn sharp left;
    }
    if(( left_feeler == 1)&&(right_feeler == 1))
    {
    Turn sharp right;
    }
    }

    -------------------------------

    Any ideas of how to do this?
     
    sHeZ123, Apr 28, 2009
    #1
    1. Advertisements

  2. sHeZ123

    sHeZ123

    Joined:
    Apr 28, 2009
    Messages:
    2
    Likes Received:
    0
    While(1)
    {
    scanf left_feeler;
    scanf right_feeler;
    if(( left_feeler==0)&&(right_feeler == 0))
    {
    Go forward;
    }
    if(( left_feeler == 1)&&(right_feeler == 0))
    {
    Turn sharp right;
    }
    if(( left_feeler == 0)&&(right_feeler == 1))
    {
    Turn sharp left;
    }
    if(( left_feeler == 1)&&(right_feeler == 1))
    {
    Turn sharp right;
    }
    }

    Is this correct?

    If so how would I add a suitable debugging code in C?
     
    sHeZ123, Apr 28, 2009
    #2
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.