Change program-1

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

    Change program-1

    I forgot to mention in my other posting that the program is suppose to
    figure out the minimum amount of different dollars and cents that
    would be required for a given amount.
  • Larry Serflaten

    #2
    Re: Change program-1

    > I forgot to mention in my other posting that the program is suppose to[color=blue]
    > figure out the minimum amount of different dollars and cents that
    > would be required for a given amount.[/color]

    Why didn't m_nickles come out right using the pattern you used for the others?

    LFS





    -----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
    http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
    -----== Over 100,000 Newsgroups - 19 Different Servers! =-----

    Comment

    • J French

      #3
      Re: Change program-1

      On Mon, 17 Nov 2003 23:24:09 -0600, "Larry Serflaten"
      <Filtered@RiskO fBeingSpam.med> wrote:
      [color=blue][color=green]
      >> I forgot to mention in my other posting that the program is suppose to
      >> figure out the minimum amount of different dollars and cents that
      >> would be required for a given amount.[/color]
      >
      >Why didn't m_nickles come out right using the pattern you used for the others?
      >[/color]

      Because he got it wrong for the rest ...

      I would not mind running into such a system
      .... reminds me of a faulty fruit machine I once ran into ...

      Comment

      • Larry Serflaten

        #4
        Re: Change program-1

        "J French" <erewhon@nowher e.com> wrote[color=blue]
        > On Mon, 17 Nov 2003 23:24:09 -0600, "Larry Serflaten"
        > <Filtered@RiskO fBeingSpam.med> wrote:
        >[color=green][color=darkred]
        > >> I forgot to mention in my other posting that the program is suppose to
        > >> figure out the minimum amount of different dollars and cents that
        > >> would be required for a given amount.[/color]
        > >
        > >Why didn't m_nickles come out right using the pattern you used for the others?[/color]
        >
        > Because he got it wrong for the rest ...[/color]

        No, the others were not wrong.

        I actually had a response typed up that would have done them in a loop, just
        as you indicated, but I remembered that students usually have to learn the
        hard way first, before finding the shortcuts and/or more efficient algorithms.
        The more important question was the nickel problem as he indicated. Solving
        that puzzle would let him continue on with the algorithm he chose, rather than
        supply him with an idea that was not his own.

        The question I posted was intended to get him to think about what the problem
        was. Why didn't the nickles fit the pattern...

        The problem was the quarters that were not fitting into the pattern he set up.
        $1.00 for example, could be determined by getting the $5.00 modulus and
        dividing that result by $1.00. That pattern works, it is not wrong for the task.

        Quarters, likewise could be obtained by getting the .50 cent modulus and
        dividing that result by .25 cents. From there on up, the values were nice
        round modulii (?) of the values above it. For example, $10 Mod $5 would
        be 0, and $20 Mod $10 would be 0. Likewise $5 Mod $1 would be 0 and
        $1 Mod .50 cents would be 0, and so forth. They all would be 0, for all values
        above itself. But 25 Mod 10 will not be 0. Those quarters screwed up the plan.

        The answer is to pull out the quarters, then the dimes, to figure the number of
        nickles.

        m_nickles = ((m_amount Mod 25) Mod 10) \ 5

        With that in place, the algorithm he chose will do the job. Even if I agree it
        could be done using fewer variables, and fewer lines of code. I think the
        solving of the nickles problem would be the better lesson at this time. Once he
        recognizes there is a pattern, he will learn soon enough that patterns can be
        applied using loops to reduce the required code.


        LFS






        -----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
        http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
        -----== Over 100,000 Newsgroups - 19 Different Servers! =-----

        Comment

        • J French

          #5
          Re: Change program-1

          Top posted - for tersity

          It was wrong - full stop

          Think about 'residue'

          If however you feel like giving me $50 change as:
          2 * $20
          + 5 * $10
          + 20 * $5
          .... etc

          Then feel free, but be prepared to re-mortgage your home

          The major problem with coding, is not coding
          - it is learning how to think.

          .... Abstraction ... Generalization .. Re-usability ..
          Compartmentaliz ation

          And, given that it was obviously homework, if one bothers to help,
          then one might as well give something that does not look too obviously
          'acquired' from a NG

          The real life answer would be :-

          Dim oChange As New cChange ' Note we know life and death
          oChange.Sum = N
          S := oChange.ScreenT ext
          oChange.PrintTe xt X, Y ' send to printer

          Of course cChange would Raise an Event to find the available
          denominations, and ... perhaps the stock holding of those
          denonimations.



          On Tue, 18 Nov 2003 08:13:01 -0600, "Larry Serflaten"
          <Filtered@RiskO fBeingSpam.med> wrote:
          [color=blue]
          >"J French" <erewhon@nowher e.com> wrote[color=green]
          >> On Mon, 17 Nov 2003 23:24:09 -0600, "Larry Serflaten"
          >> <Filtered@RiskO fBeingSpam.med> wrote:
          >>[color=darkred]
          >> >> I forgot to mention in my other posting that the program is suppose to
          >> >> figure out the minimum amount of different dollars and cents that
          >> >> would be required for a given amount.
          >> >
          >> >Why didn't m_nickles come out right using the pattern you used for the others?[/color]
          >>
          >> Because he got it wrong for the rest ...[/color]
          >
          >No, the others were not wrong.
          >
          >I actually had a response typed up that would have done them in a loop, just
          >as you indicated, but I remembered that students usually have to learn the
          >hard way first, before finding the shortcuts and/or more efficient algorithms.
          >The more important question was the nickel problem as he indicated. Solving
          >that puzzle would let him continue on with the algorithm he chose, rather than
          >supply him with an idea that was not his own.
          >
          >The question I posted was intended to get him to think about what the problem
          >was. Why didn't the nickles fit the pattern...
          >
          >The problem was the quarters that were not fitting into the pattern he set up.
          >$1.00 for example, could be determined by getting the $5.00 modulus and
          >dividing that result by $1.00. That pattern works, it is not wrong for the task.
          >
          >Quarters, likewise could be obtained by getting the .50 cent modulus and
          >dividing that result by .25 cents. From there on up, the values were nice
          >round modulii (?) of the values above it. For example, $10 Mod $5 would
          >be 0, and $20 Mod $10 would be 0. Likewise $5 Mod $1 would be 0 and
          >$1 Mod .50 cents would be 0, and so forth. They all would be 0, for all values
          >above itself. But 25 Mod 10 will not be 0. Those quarters screwed up the plan.
          >
          >The answer is to pull out the quarters, then the dimes, to figure the number of
          >nickles.
          >
          >m_nickles = ((m_amount Mod 25) Mod 10) \ 5
          >
          >With that in place, the algorithm he chose will do the job. Even if I agree it
          >could be done using fewer variables, and fewer lines of code. I think the
          >solving of the nickles problem would be the better lesson at this time. Once he
          >recognizes there is a pattern, he will learn soon enough that patterns can be
          >applied using loops to reduce the required code.
          >
          >
          >LFS
          >
          >
          >
          >
          >
          >
          >-----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
          >http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
          >-----== Over 100,000 Newsgroups - 19 Different Servers! =-----[/color]

          Comment

          • Larry Serflaten

            #6
            Re: Change program-1

            "J French" <erewhon@nowher e.com> wrote[color=blue]
            >
            > It was wrong - full stop[/color]

            No, it was not wrong. The only problem it had was being a bit verbose.
            He used more code than was necessary, but the method worked.

            [color=blue]
            > Think about 'residue'[/color]

            Try it, before you summarily dismiss it.
            [color=blue]
            >
            > If however you feel like giving me $50 change as:
            > 2 * $20
            > + 5 * $10
            > + 20 * $5[/color]

            Your calculations are off, he used the Mod operator:

            (50 Mod 50) \ 20 = 0 * $20
            (50 Mod 20) \ 10 = 0 * $10
            (50 Mod 10) \ 5 = 0 * $5

            The fact that it was a class project is precisely why I first wanted to
            prompt him to think about the problem a little more. It is common
            knowledge that to solve a problem, you first have to fully describe
            the problem, to know what it is. In programming, describing the
            problem often lends clues to the solution, which might be a good
            lesson to learn, for those just getting into their studies.

            LFS




            -----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
            http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
            -----== Over 100,000 Newsgroups - 19 Different Servers! =-----

            Comment

            • David Horne

              #7
              Re: Change program-1

              "Larry Serflaten" <Filtered@RiskO fBeingSpam.med> wrote in message news:<3fba27fd_ 5@corp.newsgrou ps.com>...[color=blue]
              > "J French" <erewhon@nowher e.com> wrote[color=green]
              > > On Mon, 17 Nov 2003 23:24:09 -0600, "Larry Serflaten"
              > > <Filtered@RiskO fBeingSpam.med> wrote:
              > >[color=darkred]
              > > >> I forgot to mention in my other posting that the program is suppose to
              > > >> figure out the minimum amount of different dollars and cents that
              > > >> would be required for a given amount.
              > > >
              > > >Why didn't m_nickles come out right using the pattern you used for the others?[/color]
              > >
              > > Because he got it wrong for the rest ...[/color]
              >
              > No, the others were not wrong.
              >
              > I actually had a response typed up that would have done them in a loop, just
              > as you indicated, but I remembered that students usually have to learn the
              > hard way first, before finding the shortcuts and/or more efficient algorithms.
              > The more important question was the nickel problem as he indicated. Solving
              > that puzzle would let him continue on with the algorithm he chose, rather than
              > supply him with an idea that was not his own.
              >
              > The question I posted was intended to get him to think about what the problem
              > was. Why didn't the nickles fit the pattern...
              >
              > The problem was the quarters that were not fitting into the pattern he set up.
              > $1.00 for example, could be determined by getting the $5.00 modulus and
              > dividing that result by $1.00. That pattern works, it is not wrong for the task.
              >
              > Quarters, likewise could be obtained by getting the .50 cent modulus and
              > dividing that result by .25 cents. From there on up, the values were nice
              > round modulii (?) of the values above it. For example, $10 Mod $5 would
              > be 0, and $20 Mod $10 would be 0. Likewise $5 Mod $1 would be 0 and
              > $1 Mod .50 cents would be 0, and so forth. They all would be 0, for all values
              > above itself. But 25 Mod 10 will not be 0. Those quarters screwed up the plan.
              >
              > The answer is to pull out the quarters, then the dimes, to figure the number of
              > nickles.
              >
              > m_nickles = ((m_amount Mod 25) Mod 10) \ 5
              >
              > With that in place, the algorithm he chose will do the job. Even if I agree it
              > could be done using fewer variables, and fewer lines of code. I think the
              > solving of the nickles problem would be the better lesson at this time. Once he
              > recognizes there is a pattern, he will learn soon enough that patterns can be
              > applied using loops to reduce the required code.
              >
              >
              > LFS
              >
              >
              >
              >
              >
              >
              > -----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
              > http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
              > -----== Over 100,000 Newsgroups - 19 Different Servers! =-----[/color]

              LFS

              I know that there was a better way than the way that I was doing it,
              but the requirements of the project forced me to do it the long way.
              (Going through each variable vs doing a loop)

              David

              Comment

              • J French

                #8
                Re: Change program-1

                On Tue, 18 Nov 2003 11:39:01 -0600, "Larry Serflaten"
                <Filtered@RiskO fBeingSpam.med> wrote:

                <snip>[color=blue]
                >
                >The fact that it was a class project is precisely why I first wanted to
                >prompt him to think about the problem a little more. It is common
                >knowledge that to solve a problem, you first have to fully describe
                >the problem, to know what it is. In programming, describing the
                >problem often lends clues to the solution, which might be a good
                >lesson to learn, for those just getting into their studies.
                >[/color]

                With the benefit of hindsight, I now follow what you said about
                Nickles

                In effect, you were saying that the rest of his code was wrong.

                .... which is quite true ...

                Comment

                • J French

                  #9
                  Re: Change program-1

                  On 18 Nov 2003 12:30:44 -0800, hornedw@yahoo.c om (David Horne) wrote:
                  <snip>[color=blue]
                  >
                  >I know that there was a better way than the way that I was doing it,
                  >but the requirements of the project forced me to do it the long way.
                  >(Going through each variable vs doing a loop)
                  >
                  >David[/color]

                  Look at it this way
                  - pretend you are writing real code - not air-ware

                  If the client is wrong you first gently explain that they are
                  arseholes
                  - if that does not work you verbally beat them up

                  In the real World - *you* are Quality Control

                  Anyway, you probably do not know this, but one common method of
                  teaching is to entice people down the wrong path
                  - and then show them the real way


                  Comment

                  Working...