I have spent over 3 hours on this and gotten most of app to execute. However, for some reason, C# has decided not to recognize my first three methods saying :<\/p>\n
Error 2 ‘HW7CH6_5.Form1.FlushCharges()’: not all code paths return a value<\/strong><\/p>\n What i can see is you are returning after every block if you can just make bit change in your code like below i believe it will work fine<\/p>\n I have spent over 3 hours on this and gotten most of app to execute. However, for some reason, C# has decided not to recognize my first three methods saying :<\/p>\n Error 2 ‘HW7CH6_5.Form1.FlushCharges()’: not all code paths return a value<\/strong><\/p>\n All of your return statements in that function are in conditional blocks (if statements). Think about what happens if:<\/p>\n chboxRadiator.Checked == false<\/p>\n and<\/p>\n chboxTransmission.Checked == false<\/p>\n To fix it you just need a return statement that is not in an if statement.<\/p>\n Another way to take care of it would be to arrange your if statements and only have 1 return statement:<\/p>\n Thanks guys.<\/p>","upvoteCount":0,"datePublished":"2013-10-29T14:26:23.000Z","url":"https://community.spiceworks.com/t/c-programming-issue/250808/4","author":{"@type":"Person","name":"jeffreybyrd9745","url":"https://community.spiceworks.com/u/jeffreybyrd9745"}},{"@type":"Answer","text":" I am still getting one more error though, there are no build errors but I am getting an exception error during the debugging process.<\/p>\n On this line (in bold and italicized)<\/p>\n private void buttonCalculate_Click(object sender, EventArgs e) System.FormatException was unhandled decimal labor = Decimal.Parse(tbxLabor.Text); is the line with problem; it works with decimal parts but not decimal labor; says i have it incorrectly formatted when decimal parts is in same format and works ???<\/p>","upvoteCount":0,"datePublished":"2013-10-29T15:01:56.000Z","url":"https://community.spiceworks.com/t/c-programming-issue/250808/6","author":{"@type":"Person","name":"jeffreybyrd9745","url":"https://community.spiceworks.com/u/jeffreybyrd9745"}},{"@type":"Answer","text":" I am still getting one more error though, there are no build errors but I am getting an exception error during the debugging process.<\/p>","upvoteCount":0,"datePublished":"2013-10-30T01:32:21.000Z","url":"https://community.spiceworks.com/t/c-programming-issue/250808/7","author":{"@type":"Person","name":"jeffreybyrd9745","url":"https://community.spiceworks.com/u/jeffreybyrd9745"}},{"@type":"Answer","text":" I would then think that tbxLabor.Text is not a String that can be converted to a decimal<\/p>","upvoteCount":0,"datePublished":"2013-11-01T17:28:27.000Z","url":"https://community.spiceworks.com/t/c-programming-issue/250808/8","author":{"@type":"Person","name":"geraldtjohnsonii","url":"https://community.spiceworks.com/u/geraldtjohnsonii"}}]}}
using System;\nusing System.Collections.Generic;\nusing System.ComponentModel;\nusing System.Data;\nusing System.Drawing;\nusing System.Linq;\nusing System.Text;\nusing System.Windows.Forms;\n\nnamespace HW7CH6_5\n{\n public partial class Form1 : Form\n {\n public Form1()\n {\n InitializeComponent();\n }\n\n public static decimal svcOilCharges = 26.0m;\n public static decimal svcLubeCharges = 18.0m;\n public static decimal svcRadiatorCharges = 30.0m;\n public static decimal svcTransmissionCharges = 80.0m;\n public static decimal svcInspectionCharges = 15.0m;\n public static decimal svcMufflerCharges = 100.0m;\n public static decimal svcTireCharges = 20.0m;\n\n public decimal OilLubeCharges()\n {\n decimal charges = 0.0m;\n if (chboxOilChange.Checked && chboxLubeJob.Checked)\n {\n charges = svcOilCharges + svcLubeCharges;\n return charges;\n }\n if (chboxOilChange.Checked)\n {\n charges = svcOilCharges;\n return charges;\n }\n if(chboxLubeJob.Checked)\n {\n charges = svcLubeCharges;\n return charges;\n }\n }\n\n public decimal FlushCharges()\n {\n decimal charges = 0.0m;\n if (chboxRadiator.Checked && chboxTransmission.Checked)\n {\n charges = svcRadiatorCharges + svcTransmissionCharges;\n return charges;\n }\n if (chboxRadiator.Checked)\n {\n charges = svcRadiatorCharges;\n return charges;\n }\n if (chboxTransmission.Checked)\n {\n charges = svcTransmissionCharges;\n return charges;\n }\n }\n\n public decimal MiscCharges()\n {\n decimal charges = 0.0m;\n if (chboxInspection.Checked && chboxMuffler.Checked && chboxTireRotation.Checked)\n {\n charges = svcInspectionCharges + svcMufflerCharges + svcTireCharges;\n return charges;\n }\n if (chboxInspection.Checked)\n {\n charges = svcInspectionCharges;\n return charges;\n }\n if (chboxMuffler.Checked)\n {\n charges = svcMufflerCharges;\n return charges;\n }\n if (chboxTireRotation.Checked)\n {\n charges = svcTireCharges;\n return charges;\n }\n }\n\n public decimal OtherCharges()\n {\n try\n {\n decimal parts = Decimal.Parse(tbxParts.Text);\n decimal labor = Decimal.Parse(tbxLabor.Text);\n decimal charges = parts + labor;\n return charges;\n }\n catch {MessageBox.Show(\"Please enter valid data for either parts or labor fields.\"); }\n return 0.0m;\n }\n\n public decimal TaxCharges()\n {\n decimal charges = 0.0m;\n decimal salesTax = 0.6m;\n {\n try\n {\n decimal taxparts = Decimal.Parse(tbxParts.Text);\n charges = taxparts * salesTax;\n return charges;\n }\n catch\n { MessageBox.Show(\"Please enter valid for parts field.\"); }\n return 0.0m;\n }\n }\n\n public decimal TotalCharges()\n {\n decimal charges = OilLubeCharges() + FlushCharges() + MiscCharges() + OtherCharges() + TaxCharges();\n return charges;\n }\n\n private void buttonCalculate_Click(object sender, EventArgs e)\n {\n decimal labor = Decimal.Parse(tbxLabor.Text);\n labelServiceLabor.Text = (OilLubeCharges()+FlushCharges()+ MiscCharges()+labor.ToString(\"C\"));\n labelParts.Text = Decimal.Parse(tbxParts.Text).ToString(\"C\");\n labelTax.Text = TaxCharges().ToString(\"C\");\n labelTotalFees.Text = TotalCharges().ToString(\"C\");\n }\n\n public void ClearOilLube()\n {\n chboxOilChange.Checked = false;\n chboxLubeJob.Checked = false;\n }\n\n public void ClearFlushes()\n {\n chboxRadiator.Checked = false;\n chboxTransmission.Checked = false;\n }\n\n public void ClearMiscCharges()\n {\n chboxInspection.Checked = false;\n chboxMuffler.Checked = false;\n chboxTransmission.Checked = false;\n }\n\n public void ClearOther()\n {\n tbxLabor.Text = \"0\";\n tbxParts.Text = \"0\";\n }\n\n public void ClearFees()\n {\n labelServiceLabor.Text = \"\";\n labelParts.Text = \"\";\n labelTax.Text = \"\";\n labelTotalFees.Text = \"\";\n }\n\n private void buttonClear_Click(object sender, EventArgs e)\n {\n ClearOilLube();\n ClearFlushes();\n ClearMiscCharges();\n ClearOther();\n ClearFees();\n }\n\n private void buttonExit_Click(object sender, EventArgs e)\n {\n //Close the form.\n this.Close();\n }\n }\n}\n\n<\/code><\/pre>","upvoteCount":4,"answerCount":8,"datePublished":"2013-10-29T04:02:04.000Z","author":{"@type":"Person","name":"jeffreybyrd9745","url":"https://community.spiceworks.com/u/jeffreybyrd9745"},"acceptedAnswer":{"@type":"Answer","text":"
public decimal FlushCharges()\n{\ndecimal charges = 0.0m;\nif (chboxRadiator.Checked && chboxTransmission.Checked)\n{\ncharges = svcRadiatorCharges + svcTransmissionCharges;\nreturn charges;\n}\nif (chboxRadiator.Checked)\n{\ncharges = svcRadiatorCharges;\nreturn charges;\n}\nif (chboxTransmission.Checked)\n{\ncharges = svcTransmissionCharges;\nreturn charges;\n}\nreturn charges;\n}\n<\/code><\/pre>","upvoteCount":0,"datePublished":"2013-10-29T05:02:49.000Z","url":"https://community.spiceworks.com/t/c-programming-issue/250808/2","author":{"@type":"Person","name":"shabirhakim8605","url":"https://community.spiceworks.com/u/shabirhakim8605"}},"suggestedAnswer":[{"@type":"Answer","text":"
using System;\nusing System.Collections.Generic;\nusing System.ComponentModel;\nusing System.Data;\nusing System.Drawing;\nusing System.Linq;\nusing System.Text;\nusing System.Windows.Forms;\n\nnamespace HW7CH6_5\n{\n public partial class Form1 : Form\n {\n public Form1()\n {\n InitializeComponent();\n }\n\n public static decimal svcOilCharges = 26.0m;\n public static decimal svcLubeCharges = 18.0m;\n public static decimal svcRadiatorCharges = 30.0m;\n public static decimal svcTransmissionCharges = 80.0m;\n public static decimal svcInspectionCharges = 15.0m;\n public static decimal svcMufflerCharges = 100.0m;\n public static decimal svcTireCharges = 20.0m;\n\n public decimal OilLubeCharges()\n {\n decimal charges = 0.0m;\n if (chboxOilChange.Checked && chboxLubeJob.Checked)\n {\n charges = svcOilCharges + svcLubeCharges;\n return charges;\n }\n if (chboxOilChange.Checked)\n {\n charges = svcOilCharges;\n return charges;\n }\n if(chboxLubeJob.Checked)\n {\n charges = svcLubeCharges;\n return charges;\n }\n }\n\n public decimal FlushCharges()\n {\n decimal charges = 0.0m;\n if (chboxRadiator.Checked && chboxTransmission.Checked)\n {\n charges = svcRadiatorCharges + svcTransmissionCharges;\n return charges;\n }\n if (chboxRadiator.Checked)\n {\n charges = svcRadiatorCharges;\n return charges;\n }\n if (chboxTransmission.Checked)\n {\n charges = svcTransmissionCharges;\n return charges;\n }\n }\n\n public decimal MiscCharges()\n {\n decimal charges = 0.0m;\n if (chboxInspection.Checked && chboxMuffler.Checked && chboxTireRotation.Checked)\n {\n charges = svcInspectionCharges + svcMufflerCharges + svcTireCharges;\n return charges;\n }\n if (chboxInspection.Checked)\n {\n charges = svcInspectionCharges;\n return charges;\n }\n if (chboxMuffler.Checked)\n {\n charges = svcMufflerCharges;\n return charges;\n }\n if (chboxTireRotation.Checked)\n {\n charges = svcTireCharges;\n return charges;\n }\n }\n\n public decimal OtherCharges()\n {\n try\n {\n decimal parts = Decimal.Parse(tbxParts.Text);\n decimal labor = Decimal.Parse(tbxLabor.Text);\n decimal charges = parts + labor;\n return charges;\n }\n catch {MessageBox.Show(\"Please enter valid data for either parts or labor fields.\"); }\n return 0.0m;\n }\n\n public decimal TaxCharges()\n {\n decimal charges = 0.0m;\n decimal salesTax = 0.6m;\n {\n try\n {\n decimal taxparts = Decimal.Parse(tbxParts.Text);\n charges = taxparts * salesTax;\n return charges;\n }\n catch\n { MessageBox.Show(\"Please enter valid for parts field.\"); }\n return 0.0m;\n }\n }\n\n public decimal TotalCharges()\n {\n decimal charges = OilLubeCharges() + FlushCharges() + MiscCharges() + OtherCharges() + TaxCharges();\n return charges;\n }\n\n private void buttonCalculate_Click(object sender, EventArgs e)\n {\n decimal labor = Decimal.Parse(tbxLabor.Text);\n labelServiceLabor.Text = (OilLubeCharges()+FlushCharges()+ MiscCharges()+labor.ToString(\"C\"));\n labelParts.Text = Decimal.Parse(tbxParts.Text).ToString(\"C\");\n labelTax.Text = TaxCharges().ToString(\"C\");\n labelTotalFees.Text = TotalCharges().ToString(\"C\");\n }\n\n public void ClearOilLube()\n {\n chboxOilChange.Checked = false;\n chboxLubeJob.Checked = false;\n }\n\n public void ClearFlushes()\n {\n chboxRadiator.Checked = false;\n chboxTransmission.Checked = false;\n }\n\n public void ClearMiscCharges()\n {\n chboxInspection.Checked = false;\n chboxMuffler.Checked = false;\n chboxTransmission.Checked = false;\n }\n\n public void ClearOther()\n {\n tbxLabor.Text = \"0\";\n tbxParts.Text = \"0\";\n }\n\n public void ClearFees()\n {\n labelServiceLabor.Text = \"\";\n labelParts.Text = \"\";\n labelTax.Text = \"\";\n labelTotalFees.Text = \"\";\n }\n\n private void buttonClear_Click(object sender, EventArgs e)\n {\n ClearOilLube();\n ClearFlushes();\n ClearMiscCharges();\n ClearOther();\n ClearFees();\n }\n\n private void buttonExit_Click(object sender, EventArgs e)\n {\n //Close the form.\n this.Close();\n }\n }\n}\n\n<\/code><\/pre>","upvoteCount":4,"datePublished":"2013-10-29T04:02:06.000Z","url":"https://community.spiceworks.com/t/c-programming-issue/250808/1","author":{"@type":"Person","name":"jeffreybyrd9745","url":"https://community.spiceworks.com/u/jeffreybyrd9745"}},{"@type":"Answer","text":"
decimal charges = 0.0m;\n\nif (chboxRadiator.Checked)\n{\ncharges = svcRadiatorCharges;\n}\n\nif (chboxTransmission.Checked)\n{\ncharges = svcTransmissionCharges;\n}\n\nif (chboxRadiator.Checked && chboxTransmission.Checked)\n{\ncharges = svcRadiatorCharges + svcTransmissionCharges;\n}\n\nreturn charges;\n<\/code><\/pre>","upvoteCount":3,"datePublished":"2013-10-29T11:28:42.000Z","url":"https://community.spiceworks.com/t/c-programming-issue/250808/3","author":{"@type":"Person","name":"cshortridge","url":"https://community.spiceworks.com/u/cshortridge"}},{"@type":"Answer","text":"
\n{
\ndecimal labor = Decimal.Parse(tbxLabor.Text);
\nlabelServiceLabor.Text = (OilLubeCharges()+FlushCharges()+ MiscCharges()+labor.ToString(“C”));
\nlabelParts.Text = Decimal.Parse(tbxParts.Text).ToString(“C”);
\nlabelTax.Text = TaxCharges().ToString(“C”);
\nlabelTotalFees.Text = TotalCharges().ToString(“C”);
\n}
\nThis is the exception error (in bold):<\/p>\n
\nHResult=-2146233033
\nMessage=Input string was not in a correct format.
\nSource=mscorlib
\nStackTrace:
\nat System.Number.StringToNumber(String str, NumberStyles options, NumberBuffer& number, NumberFormatInfo info, Boolean parseDecimal)
\nat System.Number.ParseDecimal(String value, NumberStyles options, NumberFormatInfo numfmt)
\nat System.Decimal.Parse(String s)
\nat HW7CH6_5.Form1.buttonCalculate_Click(Object sender, EventArgs e) in line 128
\nat System.Windows.Forms.Control.OnClick(EventArgs e)
\nat System.Windows.Forms.Button.OnClick(EventArgs e)
\nat System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
\nat System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
\nat System.Windows.Forms.Control.WndProc(Message& m)
\nat System.Windows.Forms.ButtonBase.WndProc(Message& m)
\nat System.Windows.Forms.Button.WndProc(Message& m)
\nat System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
\nat System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
\nat System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
\nat System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
\nat System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
\nat System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
\nat System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
\nat System.Windows.Forms.Application.Run(Form mainForm)
\nat HW7CH6_5.Program.Main() in C:\\Users\\Jeff Byrd\\documents\\visual studio 2010\\Projects\\HW7CH6-5\\HW7CH6-5\\Program.cs:line 18
\nat System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String<\/span> args)
\nat System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String<\/span> args)
\nat Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
\nat System.Threading.ThreadHelper.ThreadStart_Context(Object state)
\nat System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
\nat System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
\nat System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
\nat System.Threading.ThreadHelper.ThreadStart()
\nInnerException:<\/p>","upvoteCount":0,"datePublished":"2013-10-29T15:00:27.000Z","url":"https://community.spiceworks.com/t/c-programming-issue/250808/5","author":{"@type":"Person","name":"jeffreybyrd9745","url":"https://community.spiceworks.com/u/jeffreybyrd9745"}},{"@type":"Answer","text":"