Prime b

Prime b

  • NA
  • 810
  • 346k

lawn GUI

Dec 31 2011 3:19 PM
Help please, this the problem, I did fine console, but I have problem with GUI

Write a console-based program for a lawn-mowing service.
Th e lawn-mowing season lasts 20 weeks. Th e weekly
fee for mowing a lot under 400 square feet is $25. Th e
fee for a lot that is 400 square feet or more, but under
600 square feet, is $35 per week. Th e fee for a lot that is
600 square feet or over is $50 per week. Prompt the user
for the length and width of a lawn, and then display the
weekly mowing fee, as well as the total fee for the 20-week
season. Save the fi le as Lawn.cs.
b. Create a GUI application that performs the same functions
as those described in Exercise 7a. Save the project as
LawnGUI

This is my code

        {

            double userInPutLength, userInPutWidth, totalArea, totalArea1, totalArea2, totalArea3;
            const double weekPay = 20;

            userInPutLength = Convert.ToDouble(textBox1);
            userInPutWidth = Convert.ToDouble(textBox2);

            totalArea = userInPutLength * userInPutWidth;

            if (totalArea < 400)
            {
                totalArea1 = weekPay * 25;
                outPutLabel.Text = String.Format("For {0} square feet you have to pay {1:C}", totalArea, totalArea1);
            }
            if (totalArea >= 400 && totalArea < 600)
            {
                totalArea2 = weekPay * 35;
                outPutLabel.Text = String.Format("For {0} square feet you have to pay {1:C}", totalArea, totalArea2);

            }
            if (totalArea >= 600)
            {
                totalArea3 = weekPay * 50;
                outPutLabel.Text = String.Format("For {0} square feet you have to pay {1:C}", totalArea, totalArea3);
            }


        }
    }
}

This is my error when I click calculate button

See the end of this message for details on invoking
just-in-time (JIT) debugging instead of this dialog box.

************** Exception Text **************
System.InvalidCastException: Unable to cast object of type 'System.Windows.Forms.TextBox' to type 'System.IConvertible'.
   at System.Convert.ToDouble(Object value)
   at Chapter4Exr7b.Form1.button1_Click(Object sender, EventArgs e) in c:\users\alexander\documents\visual studio 2010\Projects\Chapter4Exr7b\Chapter4Exr7b\Form1.cs:line 25
   at System.Windows.Forms.Control.OnClick(EventArgs e)
   at System.Windows.Forms.Button.OnClick(EventArgs e)
   at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
   at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
   at System.Windows.Forms.Control.WndProc(Message& m)
   at System.Windows.Forms.ButtonBase.WndProc(Message& m)
   at System.Windows.Forms.Button.WndProc(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
   at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)


************** Loaded Assemblies **************
mscorlib
    Assembly Version: 4.0.0.0
    Win32 Version: 4.0.30319.239 (RTMGDR.030319-2300)
    CodeBase: file:///C:/Windows/Microsoft.NET/Framework/v4.0.30319/mscorlib.dll
----------------------------------------
Chapter4Exr7b
    Assembly Version: 1.0.0.0
    Win32 Version: 1.0.0.0
    CodeBase: file:///c:/users/alexander/documents/visual%20studio%202010/Projects/Chapter4Exr7b/Chapter4Exr7b/bin/Debug/Chapter4Exr7b.exe
----------------------------------------
System.Windows.Forms
    Assembly Version: 4.0.0.0
    Win32 Version: 4.0.30319.235 built by: RTMGDR
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Windows.Forms/v4.0_4.0.0.0__b77a5c561934e089/System.Windows.Forms.dll
----------------------------------------
System.Drawing
    Assembly Version: 4.0.0.0
    Win32 Version: 4.0.30319.1 built by: RTMRel
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Drawing/v4.0_4.0.0.0__b03f5f7f11d50a3a/System.Drawing.dll
----------------------------------------
System
    Assembly Version: 4.0.0.0
    Win32 Version: 4.0.30319.236 built by: RTMGDR
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System/v4.0_4.0.0.0__b77a5c561934e089/System.dll
----------------------------------------
System.Configuration
    Assembly Version: 4.0.0.0
    Win32 Version: 4.0.30319.1 (RTMRel.030319-0100)
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Configuration/v4.0_4.0.0.0__b03f5f7f11d50a3a/System.Configuration.dll
----------------------------------------
System.Xml
    Assembly Version: 4.0.0.0
    Win32 Version: 4.0.30319.233 built by: RTMGDR
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Xml/v4.0_4.0.0.0__b77a5c561934e089/System.Xml.dll
----------------------------------------

************** JIT Debugging **************
To enable just-in-time (JIT) debugging, the .config file for this
application or computer (machine.config) must have the
jitDebugging value set in the system.windows.forms section.
The application must also be compiled with debugging
enabled.

For example:

<configuration>
    <system.windows.forms jitDebugging="true" />
</configuration>

When JIT debugging is enabled, any unhandled exception
will be sent to the JIT debugger registered on the computer
rather than be handled by this dialog box.



Answers (4)