Thread: hmm, easy problem from by book.

  1. #1
    Registered User Vber's Avatar
    Join Date
    Nov 2002
    Posts
    807

    hmm, easy problem from by book.

    Hello guys

    I'am reading a book, and I do need to build a program that doe's the following things:

    Collect an logical statement:
    > (11 == 11) || (0 > 2)

    Return's true or false:
    > TRUE

    Translate the statement:
    (11 EQ 11) OR (6 LT 11)

    Here is the table:
    == : EQ
    <= : LE
    && : AND
    > : GT
    >= : GE
    | | : OR
    < : LT
    ~ : NOT
    != : NE

    Now, I don't know from where to start.
    I don't want that guys write out all my code (or part of it)

    I just need some help understanding the problem, thanks.

  2. #2
    Green Member Cshot's Avatar
    Join Date
    Jun 2002
    Posts
    892
    The problem can be broken into two parts.
    1) translating the line
    2) returning the boolean value of the statement

    I suggest you tackle part 1 first. This is rather straight forward. Parentheses and numbers do not get translated. So really, all you have to watch is the ==, !=, etc.
    You can do this by just scanning characters and printing them out as you go.

    Part 2 is a bit trickier. I suggest you do some research about precedence of operators, stacks, and recursion.
    Try not.
    Do or do not.
    There is no try.

    - Master Yoda

  3. #3
    Registered User Vber's Avatar
    Join Date
    Nov 2002
    Posts
    807

    Ok, I'll break the problem in two parts.

    Now, translating the sentence, should I get all the sentence as a string and then start translating right?

  4. #4
    Green Member Cshot's Avatar
    Join Date
    Jun 2002
    Posts
    892
    Yup. After you get that part, then you can try cases such as:

    (11 == 11) || (0 > 2)
    (11==11)||(0 >2)
    ( 11 == 11)||(0 > 2)
    etc...
    Try not.
    Do or do not.
    There is no try.

    - Master Yoda

  5. #5
    Registered User Vber's Avatar
    Join Date
    Nov 2002
    Posts
    807

    Ok, thanks for helping.

    I'll try to complete this exercise.
    anyway I think I'll need some help during solving the problem

    Thank you very much.

  6. #6
    Registered User immeraufdemhund's Avatar
    Join Date
    Dec 2002
    Posts
    12
    one quick little note about english about a and an. a is used when the next words first letter is a constanant (sp??) and an is used when a vowel shows up....not really important, but i didn't know untill 10th grade.... (i saw someone use it wrong on this thread)...

    to programming though.
    there is one command in the string.h library. It's called
    Code:
    strstr(char *s1, char *s2)
    s1 = string to look at
    s2 = string to look for in s1
    it will find the first instance of a string say >, <, == etc. this will just help you to determain if your done looking at the string. Or one thing that you could do is go through char by char and see if it's one of the operators. If it is then determain which one and change it to the appropriate sign. Show us what you got.
    Was kostet Europe, ich kaufe es!

  7. #7
    Casual Visitor
    Join Date
    Oct 2001
    Posts
    350
    Along with strstr as mentioned by immeraufdemhund, this *might* be handy at some point.

    char *cptr;
    int found;

    cptr = strstr(stringVAR, "hunted for in stringVAR");
    found = cptr - stringVAR + 1;

    English
    determine
    I
    comma usage
    you are or you're
    Last edited by ronin; 01-07-2003 at 04:28 PM.
    I haven't used a compiler in ages, so please be gentle as I try to reacclimate myself. :P

  8. #8
    Registered User Vber's Avatar
    Join Date
    Nov 2002
    Posts
    807

    Ok, thanks guys :)

    thanks.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. URGENT: Help wanted...in C
    By iamjimjohn in forum C Programming
    Replies: 16
    Last Post: 05-18-2007, 05:46 AM
  2. Easy weard C++ problem
    By Airwin in forum C++ Programming
    Replies: 4
    Last Post: 12-26-2005, 08:18 AM
  3. Replies: 20
    Last Post: 05-25-2002, 07:14 PM
  4. Newbie - MFC code from a book in VC++.Net
    By Guardian in forum Windows Programming
    Replies: 2
    Last Post: 04-27-2002, 07:17 PM
  5. easy problem with strchr-clone
    By Unregistered in forum C Programming
    Replies: 2
    Last Post: 01-03-2002, 01:45 PM