Board index » delphi » Need pascal help

Need pascal help

How can I write a program tha reads 20 digit characters(i.e, characters
in the range '0' .. '9') and counts the number of digits that are either
3,5, or 6 and that are either 1,4 or 9. Those are two separate counts.
All other digits should be ignored. Make use of the Case statement.

 

Re:Need pascal help


Quote
DarkMan40 <jlo...@popalex1.linknet.net> wrote:
>How can I write a program tha reads 20 digit characters(i.e, characters
>in the range '0' .. '9') and counts the number of digits that are either
>3,5, or 6 and that are either 1,4 or 9. Those are two separate counts.
>All other digits should be ignored. Make use of the Case statement.

Do your own homework.

Re:Need pascal help


Quote
> How can I write a program tha reads 20 digit characters(i.e, characters
> in the range '0' .. '9') and counts the number of digits that are either
> 3,5, or 6 and that are either 1,4 or 9. Those are two separate counts.
> All other digits should be ignored. Make use of the Case statement.

   Come on, do you _really_ need our help with this trivial class
assignment?  Why, it's so simple, I'd be embarrassed to devote the 20-25
seconds it would take me to actually do it...
   Besides, we don't do homework for crybaby students who won't even
demonstrate a mimimal effort to disquise a homework assignment as
something which needs and deserves real help.  Go back to class, stay
awake, read the book, and work with your teacher!

Re:Need pascal help


Quote
DarkMan40 wrote:

> How can I write a program tha reads 20 digit characters(i.e, characters
> in the range '0' .. '9') and counts the number of digits that are either
> 3,5, or 6 and that are either 1,4 or 9. Those are two separate counts.
> All other digits should be ignored. Make use of the Case statement.

This is simple.  To write the program, use an editor, e.g. the one
in the Borland Pascal integrated development environment (IDE).  You
can also use NotePad, DOS Edit or simply the one in Norton Commander.

When you have some code working, post it here if you still have
problems.  But chances are you'll find it trivial once you *start*.

- Alf

Re:Need pascal help


-=[ In:jlo...@popalex1.linkne was heard to say... ]=-

 In> How can I write a program tha reads 20 digit characters(i.e,
 In> characters  in the range '0' .. '9') and counts the number of digits
 In> that are either  3,5, or 6 and that are either 1,4 or 9. Those are two
 In> separate counts.  All other digits should be ignored. Make use of the
 In> Case statement.

How:

 1) Think out the problem at hand and how you would arrive at a solution.
 2) Write the solution in a programming language (Pascal would work fine).

        -- Kim Forwood --

  /-=oOo=--=oOo=--=oOo=--=oOo=--=oOo=--=oOo=--=oOo=--=oOo=--=oOo=--=oOo=-\
  $           Kim Forwood  <kim.forw...@access.cn.camriv.bc.ca>          %
  %         For what purpose is life, if one cannot live freely?         $
  \-=oOo=--=oOo=--=oOo=--=oOo=--=oOo=--=oOo=--=oOo=--=oOo=--=oOo=--=oOo=-/

___ Blue Wave/QWK v2.20

Re:Need pascal help


Quote
Mike Copeland wrote:
> > How can I write a program tha reads 20 digit characters(i.e, characters
> > in the range '0' .. '9') and counts the number of digits that are either
> > 3,5, or 6 and that are either 1,4 or 9. Those are two separate counts.
> > All other digits should be ignored. Make use of the Case statement.
>    Come on, do you _really_ need our help with this trivial class
> assignment?  Why, it's so simple, I'd be embarrassed to devote the 20-25
> seconds it would take me to actually do it...
>    Besides, we don't do homework for crybaby students who won't even
> demonstrate a mimimal effort to disquise a homework assignment as
> something which needs and deserves real help.  Go back to class, stay
> awake, read the book, and work with your teacher!

        That seems a little harsh to me, but i have to agree with where you're going
there. It's sad how many people abuse this group by tricking others into doing their
work for them. Just my two cents. =)

-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
      Paul Matthews - Lead Programmer : Creative Logic Software
                 http://www.singnet.com.sg/~pmatth/
                      Redcoat / FLiP '96 Coder
           http://www.science.wayne.edu/~cganir/flip.html
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

Re:Need pascal help


Quote
DarkMan40 <jlo...@popalex1.linknet.net> wrote:
>How can I write a program tha reads 20 digit characters(i.e, characters
>in the range '0' .. '9') and counts the number of digits that are either
>3,5, or 6 and that are either 1,4 or 9. Those are two separate counts.
>All other digits should be ignored. Make use of the Case statement.

Unlike all you other less than helpful individuals, I'll offer

program HowItIsNotDone(Input,Output);
const
   c                           : array [0..9] of byte
      = (0,0,0,0,0,0,0,0,0,0);
   squares                     : byte
      = 0;
var
   Digit                       : char;
   i                           : integer;
{ I wouldn't do it this way, but it works fine } begin
   while true do begin
      case EOF(Input) or EOLN(Input) of
         true : { Out of input - write out the counts } begin
            WriteLn(Output,' Number of 3''s, 5''s and 6''s
:',c[3]+c[5]+c[6]);
            WriteLn(Output,' Number of 1''s, 4''s and 9''s
:',squares);
            halt;
             end;
         false : begin
            read(Input,Digit);
            if Digit in ['3','5','6'] then Inc(c[ord(Digit)-ord('0')])
            else if frac(sqrt(ord(Digit)-ord('0'))) = 0.0 then
Inc(squares);
             end;
          end;
       end;
    end { HowItIsNotDone }.

You may have a bit of a problem explaining why you're changing the
value of a constant - c[i], or that fract(sqrt(...)) will yield 0.0
only on 1, 4 and 9. On the other hand it might be simpler to do it
yourself.

Re:Need pascal help


Quote
Paul Matthews wrote:

> Mike Copeland wrote:
> > > How can I write a program tha reads 20 digit characters(i.e, characters
> > > in the range '0' .. '9') and counts the number of digits that are either
> > > 3,5, or 6 and that are either 1,4 or 9. Those are two separate counts.
> > > All other digits should be ignored. Make use of the Case statement.
> >    Come on, do you _really_ need our help with this trivial class
> > assignment?  Why, it's so simple, I'd be embarrassed to devote the 20-25
> > seconds it would take me to actually do it...
> >    Besides, we don't do homework for crybaby students who won't even
> > demonstrate a mimimal effort to disquise a homework assignment as
> > something which needs and deserves real help.  Go back to class, stay
> > awake, read the book, and work with your teacher!

>         That seems a little harsh to me, but i have to agree with where you're going
> there. It's sad how many people abuse this group by tricking others into doing their
> work for them. Just my two cents. =)
> I can't belive this, a person ask an inocent little question & you jump on him!

Re:Need pascal help


Quote
Jeremy Johnston wrote:

> Paul Matthews wrote:

> > Mike Copeland wrote:
> > > > How can I write a program tha reads 20 digit characters(i.e, characters
> > > > in the range '0' .. '9') and counts the number of digits that are either
> > > > 3,5, or 6 and that are either 1,4 or 9. Those are two separate counts.
> > > > All other digits should be ignored. Make use of the Case statement.
> > >    Come on, do you _really_ need our help with this trivial class
> > > assignment?  Why, it's so simple, I'd be embarrassed to devote the 20-25
> > > seconds it would take me to actually do it...
> > >    Besides, we don't do homework for crybaby students who won't even
> > > demonstrate a mimimal effort to disquise a homework assignment as
> > > something which needs and deserves real help.  Go back to class, stay
> > > awake, read the book, and work with your teacher!

> >         That seems a little harsh to me, but i have to agree with where you're going
> > there. It's sad how many people abuse this group by tricking others into doing their
> > work for them. Just my two cents. =)
> > I can't belive this, a person ask an inocent little question & you jump on him!

   That's _not_ an "innocent little question" - it's clearly a school
programming exercise...nothing more.  Look at how it's worded, to see
that the requirements (!) state that a Case statement should be used. Any
legitimate request for help would (1) not be so specific, (2) be written
in a tone of, "I can't get the following to work...", and (3) show the
code or effort taken by the individual to get to the "blocking" point.  
These blatant homework-help beggings/grovelings don't deserve the time I
spend answering them, but I try to set a better standard here than these
things show.  I (and many others here) will gladly offer help for real
problems, but the obvious posts of indolent students - who seem far out
matched by even attending class lectures and reading the text - tend to
p*ss me off.  That's not how I got through school, nor is it how I'm
making my way though Life...

Other Threads