example of a logic bug using pseudocode

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • popeyerayaz

    #1

    example of a logic bug using pseudocode

    I want run this by the group for correctness.
    The question is as follows:

    9. Present an example of a logic bug using pseudocode and explain your
    answer. (10 points)


    Temperature = 70
    if (Temperature >69) and (Temperature < 100 )
    THEN
    openWindows;
    Will work because if temperature is higher than 69 degrees and
    temperature is lower than 100 degrees windows will open.
    2. Gentlemen, after reading your advise I had run the code in C++,
    then stated it back in pseudocode. I suppose the programmer could
    mistakenly use the "AND" && operator instead of the "OR" || operator
    which I found the latter to run a loop which I couldn't end, not even
    with a ctrl-c, and had to push the power button in to turn off my
    computer (please keep that in mind). Also found that the temperatures
    reflected would better reflect opening the windows and not closing
    them.

    Temperature = 70
    if (Temperature >69) and (Temperature < 100 )
    THEN
    openWindows;
    Will work because if temperature is higher than 69 degrees and
    temperature is lower than 100 degrees windows will open.

    The code generated: numbered list 70-99

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

    Temperature = 70
    if (Temperature >69) or (Temperature < 100 )
    THEN
    openWindows;

    Won't work because windows will stay closed due to temperature will
    always be under 100 degrees the fault lies with the "or" "||" operator
    which was used instead of the "and" (&&) operator.
    The code generated: an infinite loop of never ending numbers that
    crashed my computer.

    Thank You,

    Ray The code generated: numbered list

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

    Temperature = 70
    if (Temperature >69) or (Temperature < 100 )
    THEN
    openWindows;

    Won't work because windows will stay closed due to temperature will
    always be under 100 degrees the fault lies with the "or" "||" operator
    which was used instead of the "and" (&&) operator.
    The code generated: an infinite loop of never ending numbers that
    crashed my computer.

    Thank You,

    Ray
  • Richard Heathfield

    #2
    Re: example of a logic bug using pseudocode

    popeyerayaz said:

    <snip>
    I suppose the programmer could
    mistakenly use the "AND" && operator instead of the "OR" || operator
    which I found the latter to run a loop which I couldn't end, not even
    with a ctrl-c, and had to push the power button in to turn off my
    computer (please keep that in mind).
    Modern multi-tasking computer systems generally provide some way to
    terminate a process from outside the process itself. For example, on
    Windows you could have brought up the Task Manager (Ctrl-Alt-Del
    nowadays), identified the process, selected it, and terminated it. Under
    Linux, you could have used ps -eaf | grep <tasknameto find the task's
    process ID (pid) and then used kill -9 <pidto terminate the task.

    --
    Richard Heathfield <http://www.cpax.org.uk >
    Email: -http://www. +rjh@
    Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
    "Usenet is a strange place" - dmr 29 July 1999

    Comment

    • Nick Keighley

      #3
      Re: example of a logic bug using pseudocode

      On 22 Jul, 06:55, popeyerayaz <popeyera...@gm ail.comwrote:

      your post is very confusing
      I want run this by the group for correctness.
      The question is as follows:
      >
      9. Present an example of a logic bug using pseudocode and explain your
      answer. (10 points)
      >
      Temperature = 70
       if (Temperature >69) and (Temperature < 100 )
              THEN
          openWindows;
      else
      openLinux

      :-)

      Will work because if temperature is higher than 69 degrees and
      temperature is lower than 100 degrees windows will open.
      2. Gentlemen, after reading your advise [advice?] I had run the code in C++,
      what gentlemen? what advice?

      then stated it back in pseudocode. I suppose the programmer could
      mistakenly use the "AND" && operator instead of the "OR" || operator
      which I found the latter to run a loop which I couldn't end,
      how the hell can the above p-code loop??!

      not even
      with a ctrl-c, and had to push the power button in to turn off my
      computer (please keep that in mind).
      I think you need a new computer.
      Also found that the temperatures
      reflected would better reflect opening the windows and not closing
      them.
      what does "temperatur e reflected" mean? The code you've posted
      doesn't close windows.

      Temperature = 70
       if (Temperature >69) and (Temperature < 100 )
              THEN
          openWindows;
      Will work because if temperature is higher than 69 degrees and
      temperature is lower than 100 degrees windows will open.
      why did you post this twice?

      The code generated: numbered list 70-99
      what?

      ---------------------------------------------------------------------------­---------------------------------------------------------------------------
      >
      Temperature = 70
       if (Temperature >69) or (Temperature < 100 )
              THEN
         openWindows;
      >
      Won't work because windows will stay closed due to temperature will
      always be under 100 degrees the fault lies with the "or" "||" operator
      which was used instead of the "and" (&&) operator.
      The code generated:  an infinite loop of never ending numbers that
      crashed my computer.
      there is no loop in the above code


      Thank You,
      >
      Ray The code generated: numbered list
      >
      ---------------------------------------------------------------------------­---------------------------------------------------------------------------­---------------------------
      >
      Temperature = 70
       if (Temperature >69) or (Temperature < 100 )
              THEN
         openWindows;
      >
      Won't work because windows will stay closed due to temperature will
      always be under 100 degrees the fault lies with the "or" "||" operator
      which was used instead of the "and" (&&) operator.
      The code generated:  an infinite loop of never ending numbers that
      crashed my computer.
      >
      Thank You,
      >
      Ray
      why did you post this twice?


      --
      Nick Keighley



      Comment

      • Richard

        #4
        Re: example of a logic bug using pseudocode

        Nick Keighley <nick_keighley_ nospam@hotmail. comwrites:
        On 22 Jul, 06:55, popeyerayaz <popeyera...@gm ail.comwrote:
        >
        your post is very confusing
        >
        >I want run this by the group for correctness.
        >The question is as follows:
        >>
        >9. Present an example of a logic bug using pseudocode and explain your
        >answer. (10 points)
        >>
        >Temperature = 70
        > if (Temperature >69) and (Temperature < 100 )
        >        THEN
        >    openWindows;
        >
        else
        openLinux
        >
        :-)
        >
        >
        >Will work because if temperature is higher than 69 degrees and
        >temperature is lower than 100 degrees windows will open.
        >2. Gentlemen, after reading your advise [advice?] I had run the code in C++,
        >
        what gentlemen? what advice?
        >
        >
        >then stated it back in pseudocode. I suppose the programmer could
        >mistakenly use the "AND" && operator instead of the "OR" || operator
        >which I found the latter to run a loop which I couldn't end,
        >
        how the hell can the above p-code loop??!
        >
        >
        >not even
        >with a ctrl-c, and had to push the power button in to turn off my
        >computer (please keep that in mind).
        >
        I think you need a new computer.
        >
        >Also found that the temperatures
        >reflected would better reflect opening the windows and not closing
        >them.
        >
        what does "temperatur e reflected" mean? The code you've posted
        doesn't close windows.
        >
        >
        >Temperature = 70
        > if (Temperature >69) and (Temperature < 100 )
        >        THEN
        >    openWindows;
        >Will work because if temperature is higher than 69 degrees and
        >temperature is lower than 100 degrees windows will open.
        >
        why did you post this twice?
        >
        >
        >The code generated: numbered list 70-99
        >
        what?
        Is the sole reason for your reply to be rude, obnoxious and generally
        show off? If so, well done. 10/10.

        Comment

        • Kenny McCormack

          #5
          Re: example of a logic bug using pseudocode

          In article <g64eb9$tm8$3@r egistered.motza rella.org>,
          Richard <rgrdev@gmail.c omresponded to that jerky Nick Keighley
          <nick_keighley_ nospam@hotmail. comthusly:
          ....
          >Is the sole reason for your reply to be rude, obnoxious and generally
          >show off? If so, well done. 10/10.
          Of course it is. Is there (quite seriously) any other reason to post to
          clc?

          (And you should have seen the smile on his face when he did it...)

          Comment

          • rahul

            #6
            Re: example of a logic bug using pseudocode

            On Jul 22, 10:55 am, popeyerayaz <popeyera...@gm ail.comwrote:
            <snip>
            You aren't making much sense. Please re-phrase your question in a way
            that everyone can understand it. And try posting to the point.

            Comment

            • Nick Keighley

              #7
              Re: example of a logic bug using pseudocode

              On 22 Jul, 11:55, Richard<rgr...@ gmail.comwrote:
              Nick Keighley <nick_keighley_ nos...@hotmail. comwrites:
              On 22 Jul, 06:55, popeyerayaz <popeyera...@gm ail.comwrote:
              >
              your post is very confusing
              >
              I want run this by the group for correctness.
              The question is as follows:
              >
              9. Present an example of a logic bug using pseudocode and explain your
              answer. (10 points)
              >
              Temperature = 70
               if (Temperature >69) and (Temperature < 100 )
                      THEN
                  openWindows;
              >
              else
                  openLinux
              >
              :-)
              >
              Will work because if temperature is higher than 69 degrees and
              temperature is lower than 100 degrees windows will open.
              2. Gentlemen, after reading your advise [advice?] I had run the code in C++,
              >
              what gentlemen? what advice?
              >
              then stated it back in pseudocode. I suppose the programmer could
              mistakenly use the "AND" && operator instead of the "OR" || operator
              which I found the latter to run a loop which I couldn't end,
              >
              how the hell can the above p-code loop??!
              >
              not even
              with a ctrl-c, and had to push the power button in to turn off my
              computer (please keep that in mind).
              >
              I think you need a new computer.
              >
              Also found that the temperatures
              reflected would better reflect opening the windows and not closing
              them.
              >
              what does "temperatur e reflected" mean? The code you've posted
              doesn't close windows.
              >
              Temperature = 70
               if (Temperature >69) and (Temperature < 100 )
                      THEN
                  openWindows;
              Will work because if temperature is higher than 69 degrees and
              temperature is lower than 100 degrees windows will open.
              >
              why did you post this twice?
              >
              The code generated: numbered list 70-99
              >
              what?
              >
              Is the sole reason for your reply to be rude, obnoxious and generally
              show off? If so, well done. 10/10.- Hide quoted text -
              oh course. :-)

              if he wants help (I assume that's why he posted to comp.lang.c)
              then he's going to have to ask a clear question. His post seemed
              to be part of a longer converstation or had been extracted from
              another post. I found it unclear. Perhaps if he asked a clear
              question he'd get better help. Improving his ability to ask
              questions might even make him a better programmer.

              What was your reason for posting?


              --
              Nick Keighley

              When it comes to feeding trolls, taking offense at their posts is
              like serving them Lobster Thermidor aux Crevettes with Mornay sauce
              served in a Provencale manner with shallots and aubergines garnished
              with truffle pate, brandy and with a fried egg on top and Spam.

              Comment

              • vippstar@gmail.com

                #8
                Re: example of a logic bug using pseudocode

                On Jul 22, 2:57 pm, Nick Keighley <nick_keighley_ nos...@hotmail. com>
                wrote:
                <snip reply to troll>
                What was your reason for posting?
                Trolling.
                When it comes to feeding trolls, taking offense at their posts is
                like serving them Lobster Thermidor aux Crevettes with Mornay sauce
                served in a Provencale manner with shallots and aubergines garnished
                with truffle pate, brandy and with a fried egg on top and Spam.
                s/taking offense/replying

                Comment

                Working...