C
CMNick
Guest
My assignment is to write a GUI program that allows a user to input the number of eggs produced in a month by each of five chickens. Sum the eggs, then display the total in dozens and eggs. For example, a total of 127 eggs is 10 dozen and 7 eggs. Following is the code I have written so far. Im not sure how to end it so that the correct results display. I have 2 options listed at the end separated by the word (OR). Please look it over and let me know if Im correct or what Im missing. Thank you!
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace EggsInteractiveGUI
{
public partial class eggCalculator : Form
{
public eggCalculator()
{
InitializeComponent();
}
private void calculateButton_Click(object sender, EventArgs e)
{
int sum, dozens, remainder, eggs1, eggs2, eggs3, eggs4, eggs5;
eggs1 = Convert.ToInt32(eggCount1.Text);
eggs2 = Convert.ToInt32(eggCount2.Text);
eggs3 = Convert.ToInt32(eggCount3.Text);
eggs4 = Convert.ToInt32(eggCount4.Text);
eggs5 = Convert.ToInt32(eggCount5.Text);
int sum = eggs1 + eggs2 + eggs3 + eggs4 + eggs5;
int dozens = sum / 12;
int remainder = sum % 12;
totalEggs.Text("Dozens: " + dozens.ToString() + ", Remainder: " + remainder.ToString());
(OR) totalEggs.Text = "{0} eggs is {1} dozen with {2} left over.";
totalEggs.Visible = true;
}
}}
Continue reading...
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace EggsInteractiveGUI
{
public partial class eggCalculator : Form
{
public eggCalculator()
{
InitializeComponent();
}
private void calculateButton_Click(object sender, EventArgs e)
{
int sum, dozens, remainder, eggs1, eggs2, eggs3, eggs4, eggs5;
eggs1 = Convert.ToInt32(eggCount1.Text);
eggs2 = Convert.ToInt32(eggCount2.Text);
eggs3 = Convert.ToInt32(eggCount3.Text);
eggs4 = Convert.ToInt32(eggCount4.Text);
eggs5 = Convert.ToInt32(eggCount5.Text);
int sum = eggs1 + eggs2 + eggs3 + eggs4 + eggs5;
int dozens = sum / 12;
int remainder = sum % 12;
totalEggs.Text("Dozens: " + dozens.ToString() + ", Remainder: " + remainder.ToString());
(OR) totalEggs.Text = "{0} eggs is {1} dozen with {2} left over.";
totalEggs.Visible = true;
}
}}
Continue reading...