Lesson Six, The Farmer Problem (you must use the Select Case logic in your answer):
A farmer would you like to create a program that would calculate the amount of feed each of the three types of animals they raise requires each day. The formulas are based upon the type of animal and the animals weight. The only difference is when it comes to pigs. Female pigs require 10% more of each ingredient than the male pigs because they are always either pregnant or nursing. The following is the formulas (based upon the percent of the animals weight). For horses : Alfalfa 5% (of the horse's weight), Oats 10%, Hay 20%, Whey 5%; Cows: Alfalfa 10%, Oats 20%, Hay 30%, Whey 10%; Pigs: Alfalfa 15%, Oats 20%, Hay 30%, Whey 15%. The program would only evaluate one animal at a time and let the farmer know what type of animal it is, how much it weighs, and how much of each ingredient would be required.
You must do five things with the problem (problem statement, human algorithm, data dictionary, flowchart, code:
1. Develop a problem statement:
a. Assumptions
b. Input
c. Calculations
d. Output
Answer
a. Assumptions:
1. Only one type of animal at a time
2. Only one day of feed is calculated
3. Female pigs get 10% extra
b. Input:
1. animal type
2. Animal weight
3. If Pig then animal gender
c. Calculations:
If horse: Alfalfa = wt * .05, Oats = wt * .1, Hay = wt * .2,
Whey = wt * .05
If Cow: Alfalfa = wt * .1, Oats= wt * .2, Hay = wt * .3, Whey= wt *
.1
If Pig:
If male: Alfalfa= wt * .15, Oats= wt * .2, Hay= wt *
.3, Whey= wt * .15
If female: Alfalfa= wt * .15 * 1.10, Oats= wt * .2 *
1.10, Hay= wt * .3 * 1.10, Whey= wt * .15 * 1.10
d. Output:
1. type of animal
2. Weight
3. Amount of Alfalfa
4. Amount of Oats
5. Amount of Hay
6. Amount of Whey
Write a human algorithm (step by step process
for solving this problem. Remember you must make each step simple, don't
try and combine steps, break everything down to it's simplest form.)
answer
Human Algorithm:
1. Ask for animal type
2. Ask for animal weight
3.
a. If horse: Alfalfa = wt * .05, Oats = wt
* .1, Hay = wt * .2, Whey = wt * .05
b. If Cow: Alfalfa = wt * .1, Oats= wt *
.2, Hay = wt * .3, Whey= wt * .1
c. If Pig:
(1). If male: Alfalfa= wt *
.15, Oats= wt * .2, Hay= wt * .3, Whey= wt * .15
(2). If female: Alfalfa=
wt * .15 * 1.10, Oats= wt * .2 * 1.10, Hay= wt * .3 * 1.10, Whey= wt * .15 *
1.10
4. Output the type of animal
5. Output the Weight
6. Output the Amount of Alfalfa
7. Output the Amount of Oats
8. Output the Amount of Hay
9. Amount of Whey
3. Flow Chart: You can't use
visual logic to display select case so we are displaying it has if...elseif...else
but coding it using Select Case.

4. Data Dictionary with data types: For example "number1 (num), name1(text)
Animal (text), weight (num), alfalfa (num), Oats (num), hay (num), Whey (num), gender (text)
5. Create the VB Script that will solve
this problem:
Answer
Code
<Script language="vbscript">
Option Explicit
DIM Animal, Weight, Alfalfa, Oats, Hay, Whey, Gender
Animal=inputbox("What type of animal is it? Horse, Cow, or Pig")
Weight=cint(inputbox("How much does it weigh?"))
Select Case Animal
Case "Horse"
Alfalfa = Weight * .05
Oats = Weight * .10
Hay = weight * .20
Whey = Weight * .05
Case "Cow"
Alfalfa = Weight * .10
Oats = Weight * .20
Hay = weight * .30
Whey = Weight * .10
Case "Pig"
Gender=inputbox("Is the pig female or male?")
If Gender="female" then
Alfalfa = (Weight * .15) + (Weight * .10)
Oats = (Weight * .20) + (Weight * .10)
Hay = (weight * .30) + (Weight * .10)
Whey = (Weight * .15) + (Weight * .10)
Else
Alfalfa = Weight * .15
Oats = Weight * .20
Hay = weight * .30
Whey = Weight * .15
End if
End Select
Document.write"<p>The animal is a " & Gender & Animal & "."
Document.write"<p>The animal's weight is " & Weight & "."
Document.write"<p>You need to feed it " & Alfalfa & "percent of Alfalfa."
Document.write"<p>You need to feed it " & Oats & "percent of Oats."
Document.write"<p>You need to feed it " & Hay & "percent of Hay."
Document.write"<p>You need to feed it " & Whey & "percent of Whey."
</script>