rozdial drugi cw. 2
MathsOperators
dlaczego w każdym z kawałków kodu występuje int outcome = 0
skoro potem przypisujemy do outcome działanie arytmetyczne np. outcome = lhs + rhs
public sealed partial class MainPage : Page
{
public MainPage()
{
this.InitializeComponent();
}
private void calculateClick(object sender, RoutedEventArgs e)
{
try
{
if ((bool)addition.IsChecked)
{
addValues();
}
else if ((bool)subtraction.IsChecked)
{
subtractValues();
}
else if ((bool)multiplication.IsChecked)
{
multiplyValues();
}
else if ((bool)division.IsChecked)
{
divideValues();
}
else if ((bool)remainder.IsChecked)
{
remainderValues();
}
}
catch (Exception caught)
{
expression.Text = "";
result.Text = caught.Message;
}
}
private void addValues()
{
int lhs = int.Parse(lhsOperand.Text);
int rhs = int.Parse(rhsOperand.Text);
int outcome = 0;
// TODO: Add rhs to lhs and store the result in outcome
outcome = lhs + rhs;
expression.Text = $"{lhsOperand.Text} + {rhsOperand.Text}";
result.Text = outcome.ToString();
}
private void subtractValues()
{
int lhs = int.Parse(lhsOperand.Text);
int rhs = int.Parse(rhsOperand.Text);
int outcome = 0;
// TODO: Subtract rhs from lhs and store the result in outcome
outcome = lhs - rhs
expression.Text = $"{lhsOperand.Text} - {rhsOperand.Text}";
result.Text = outcome.ToString();
}
private void multiplyValues()
{
int lhs = int.Parse(lhsOperand.Text);
int rhs = int.Parse(rhsOperand.Text);
int outcome = 0;
// TODO: Multiply lhs by rhs and store the result in outcome
outcome = lhs * rhs;
expression.Text = $"{lhsOperand.Text} * {rhsOperand.Text}";
result.Text = outcome.ToString();
}
private void divideValues()
{
int lhs = int.Parse(lhsOperand.Text);
int rhs = int.Parse(rhsOperand.Text);
int outcome =0;
// TODO: Divide lhs by rhs and store the result in outcome
outcome = lhs / rhs;
expression.Text = $"{lhsOperand.Text} / {rhsOperand.Text}";
result.Text = outcome.ToString();
}
private void remainderValues()
{
int lhs = int.Parse(lhsOperand.Text);
int rhs = int.Parse(rhsOperand.Text);
int outcome = 0;
// TODO: Work out the remainder after dividing lhs by rhs and store the result in outcome
outcome = lhs % rhs
expression.Text = $"{lhsOperand.Text} % {rhsOperand.Text}";
result.Text = outcome.ToString();
dlaczego w każdym z kawałków kodu występuje int outcome = 0
skoro potem przypisujemy do outcome działanie arytmetyczne np. outcome = lhs + rhs