Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy won't this insurance calculator display output when it's run in Visual Studio 2012? (It debugs perfectly)
    text
    copied!<p>Forgive me if I come across as amateurish, only been doing this for a few weeks. I have to build an application that calculates monthly insurance monthly and total premiums based on age, and insurance plan selected. </p> <p>I made a few methods before the calcButton_click event, including;</p> <p>i) ageCatTest to determine the age category the client belonged to.</p> <p>ii) deductibleChoice to determine which deductible they would pay (0, 75, or 100). I figured putting all 3 in a listbox would be easier than trying to write code to contain answers outside those 3 options.</p> <p>iii) planChoice to determine which plan has been selected (A or B). I also used a listbox to try and contain the realm of possible answers. </p> <p>I set all the possible monthly premiums in a two-dimensional array, with row[0] corresponding to plan A and row[1] corresponding to plan B. Columns [0,1,2,3,4] correspond to the age category (ageCat). I then tried to set it up so the value was selected from the array using the result of the ageCat method and the planChoice method as index keys. </p> <p>Lastly once the premium is determined it is multiplied by a potential discount (if the user selects either 75 or 100 as a deductible in the listbox, not 0).</p> <p>The results of all this is supposed to be displayed in a few textboxes when the calcButton_click is activated, but this isn't the case. It doesn't freeze up or lag when I hit calculate, nothing happens. </p> <p>Visual Studio cannot find any errors and as far as the compiler is concerned there are none. However, since nothing is happening I'm assuming there's something wrong with the way I've structured either the methods or the click_event, but I can't find any. If anyone can spot any obvious mistakes it would be much appreciated.</p> <p>Thank you!</p> <pre><code>namespace InsuranceApp { public partial class insuranceCalculator : Form { public insuranceCalculator() { InitializeComponent(); } private bool planChoice(string plan) { bool planType = false; if (plan.Equals("B")) { planType = true; return planType; } return planType; } private decimal deductibleChoice(string deductibleSelect) { decimal discount; discount = 1; switch (deductibleSelect) { case "75": discount = 0.95m; return discount; case "100": discount = 0.92m; return discount; } return discount; } private int ageCatTest(int age) { int ageCat = 0; if (age &gt;= 36 &amp;&amp; age &lt;= 45) { ageCat = 1; return ageCat; } else if (age &gt;= 46 &amp;&amp; age &lt;= 55) { ageCat = 2; return ageCat; } else if (age &gt;= 56 &amp;&amp; age &lt;= 65) { ageCat = 3; return ageCat; } else if (age &gt;= 66 &amp;&amp; age &lt;= 75) { ageCat = 4; return ageCat; } return ageCat; } private void calcButton_Click(object sender, EventArgs e) { int[,] plans = {{80, 90, 110, 140, 170}, {100, 110, 125, 170, 210}}; int ageCat; int planType = 0; int age; decimal discount; string deductible; decimal coverage = 100000; decimal monthlyPremium; int months; string plan; decimal totalPremium; if (int.TryParse((ageTextBox.Text), out age)) { if (age &lt; 18 || age &gt; 75) { MessageBox.Show("Sorry, you are ineligible for travel insurance."); } else { if (int.TryParse((monthsTextBox.Text), out months)) { ageCat = ageCatTest(age); plan = planListBox.SelectedItem.ToString(); if (planChoice(plan) == true) { planType = 1; coverage = 150000; } coverageTextBox.Text = coverage.ToString("n2"); deductible = deducSelBox.SelectedItem.ToString(); discount = deductibleChoice(deductible); monthlyPremium = plans[planType, ageCat]; monthlyPremium = monthlyPremium * discount; premiumTextBox.Text = monthlyPremium.ToString("n2"); totalPremium = monthlyPremium * months; totalPremTextBox.Text = totalPremium.ToString("n2"); } } } } private void exitButton_Click(object sender, EventArgs e) { this.Close(); } } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload