Board index » delphi » problem

problem

Hi,

I'm taking Pascal, and to my surprise I'm actually enjoying it:)
I am working on a program and I'm stuck bigtime on one part of it. I
have poured over the textbook a zillion times, and went to the library
today to look at other pascal books.

The problem is:

The user (a rancher) would have to type in a cows ID and weight . The
cows are black, red, and white...so the first character has to be B,or
R, or W..the other three can be whatever.. letters or numbers. In total
4!
What this program does is average the weight of the black cows, red, and
white. I understand how to do the program except for the part of the
cows ID. How do I do it so it knows that B is a black cow, R..red,
W..white? What about those last three letters, or numbers? In my
assignment it says we should'nt have to use arrays. I have been
declaring them a String....

Thanks

 

Re:problem


Quote
Little Lamb <p...@connect.ab.ca> wrote:
>The user (a rancher) would have to type in a cows ID and weight . The
>cows are black, red, and white...so the first character has to be B,or
>R, or W..the other three can be whatever.. letters or numbers. In total
>4!
>What this program does is average the weight of the black cows, red, and
>white. I understand how to do the program except for the part of the
>cows ID. How do I do it so it knows that B is a black cow, R..red,
>W..white? What about those last three letters, or numbers? In my
>assignment it says we should'nt have to use arrays. I have been
>declaring them a String....

If you aren't expected to use an array then you'll have to maintain
separate variables for the weight and count of each color cow.
Maybe something like BlackWeight, BlackCount, RedWeight, RedCount,
etc.  You could then use a case statement to determine which color
cow you have so you could update the appropriate set of variables.

Assuming that CowID is a string, then --

   Case UpCase(CowID[1]) of
     'B': Begin ... End;
     'W': Begin ... End;
     'R': Begin ... End;
     Else --- what do you want to do if the entry is bad? ---
   End{Case};

The problem only requires you to be concerned with a cow's color.
Since there is no requirement to do anything with the rest of the
cow's ID, you can simply ignore it.  

BTW, don't forget to initialize/clear all variable before you being
counting.

    ...red

--
Support the anti-Spam amendment
  Join at http://www.cauce.org/

Re:problem


Thanks!!  It's all finished and running:)

Other Threads