Here is what i have so far! i need to display the string array as well as the to
ID: 3692420 • Letter: H
Question
Here is what i have so far! i need to display the string array as well as the totalFees.
I have got the totalFees to display in the second form but i'm having trouble with the String array
public partial class Main : Form
{
// Array to hold totals
decimal[] dormFees = { 1500, 1600, 1800, 2500 };
decimal[] mealFees = { 600, 1200, 1700, };
// Strins to hold names of
string[] dormitories = { "Allen Hall", "Pike Hall", "Farthing Hall", "University Hall"};
string[] mealPlans = { "7 meals", "14 meals", "Unlimited meals"};
string allen, pike, farthing, university, seven, fourteen, unlimited;
//bool arraysEqual = true; //
public Main()
{
InitializeComponent();
}
private void btnCalculate_Click(object sender, EventArgs e)
{
decimal dormFeesTotal = 0m;
decimal mealFeesTotal = 0m;
if (allenCheckBox.Checked)
{
dormFeesTotal = dormFees[0];
allen = dormitories[0];
}
else if (pikeCheckBox.Checked)
{
dormFeesTotal = dormFees[1];
pike = dormitories[1];
}
else if (farthingCheckBox.Checked)
{
dormFeesTotal = dormFees[2];
farthing = dormitories[2];
}
else if (suitesCheckBox.Checked)
{
dormFeesTotal = dormFees[3];
university = dormitories[3];
}
if (checkBox5.Checked)
{
mealFeesTotal = mealFees[0];
}
else if (checkBox6.Checked)
{
mealFeesTotal = mealFees[1];
}
else if (checkBox7.Checked)
{
mealFeesTotal = mealFees[2];
}
else
{
MessageBox.Show("Please choose a meal");
}
decimal totalFees = dormFeesTotal + mealFeesTotal;
//string[] dormitories;
// Create an instatnce of Totalsform class
TotalsForm totalsMessage = new TotalsForm(totalFees, dormitories);
totalsMessage.ShowDialog();
//totalsMessageForm.totals = new TotalsForm();
//listBoxTotal.Text = totals.Total;
//totalsMessageForm.ShowDialog();
}
private void Main_Load(object sender, EventArgs e)
{
// Strins to hold names of
//string[] dormitories = { "Allen Hall", "Pike Hall", "Farthing Hall", "University Hall"};
//string[] mealPlans = { "7 meals", "14 meals", "Unlimited meals"};
}
}
}
////second form
public partial class TotalsForm : Form
{
decimal totalFees;
private string[] dormitories1;
private string dormitories;
public TotalsForm(decimal totalFees, string dormitories1)
{
this.totalFees = totalFees;
this.dormitories1 = dormitories1;
InitializeComponent();
listBoxTotal.Text = totalFees.ToString(("C") + dormitories);
}
public TotalsForm(decimal totalFees, string[] dormitories1)
{
this.totalFees = totalFees;
this.dormitories1 = dormitories1;
}
private void btnExit_Click(object sender, EventArgs e)
{
// Close the form
this.Close();
}
}
}
Explanation / Answer
In Total Form Constructor you are expecting String as argument but assigning it's value to String array
public TotalsForm(decimal totalFees, string dormitories1)
{
this.totalFees = totalFees;
this.dormitories1 = dormitories1;
InitializeComponent();
listBoxTotal.Text = totalFees.ToString(("C") + dormitories);
}
So Either you have to change the datatype of dormitories1 to String or change Constructor as
public TotalsForm(decimal totalFees, String[] dormitories1)
{
this.totalFees = totalFees;
this.dormitories1 = dormitories1;
InitializeComponent();
listBoxTotal.Text = totalFees.ToString(("C") + dormitories);
}
Also it seems code is incomplete and with a lot of Syntax errors . If Problem is still not resolved, Please Update Question with all Correct Class Files .