I have gone through the "Do This" but the program still isn't running as your books says it should. On page 205, the book says that I should be able to change my NumericUpDown control and it will change the output after I press the Calculate button. My program is not doing that and I have checked everything multiple times.
My program doesn't seem to be setting the value of "numberOfCows" to anything other than its default, even after I have changed that value through the NumericUpDown. I'm baffled. I'm familiar with C++ and I understand what the properities of "public int NumberOfCows" should be doing, but it does not seem to be doing what it is supposed to.
Here is my Form1.cs:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace Chap5_DoThis
{
public partial class Form1 : Form
{
Farmer farmer;
public Form1()
{
InitializeComponent();
farmer = new Farmer() { NumberOfCows = 15 };
}
private void numericUpDown1_ValueChanged(object sender, EventArgs e)
{
farmer.NumberOfCows = (int)numericUpDown1.Value;
}
private void calculate_Click(object sender, EventArgs e)
{
Console.WriteLine("I need {0} bags of feed for {1} cows", farmer.BagsOfFeed, farmer.NumberOfCows);
}
}
}
Here is my Farmer.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Chap5_DoThis
{
class Farmer
{
public int BagsOfFeed;
public const int FEED_MULTIPLIER = 30;
private int numberOfCows;
public int NumberOfCows
{
get
{
return numberOfCows;
}
set
{
numberOfCows = value;
BagsOfFeed = numberOfCows * FEED_MULTIPLIER;
}
}
}
}











