@@ -19,30 +19,87 @@ public Form1()
19
19
20
20
private void plusButton_Click ( object sender , EventArgs e )
21
21
{
22
- double first = Convert . ToDouble ( value1 . Text ) ;
23
- double second = Convert . ToDouble ( value2 . Text ) ;
24
- resultBox . Text = Convert . ToString ( first + second ) ;
22
+
23
+ if ( value1 . Text == "" || value2 . Text == "" )
24
+ {
25
+ resultBox . Text = "Error: Please enter two valid values" ;
26
+ }
27
+ else
28
+ {
29
+ try
30
+ {
31
+ double first = Convert . ToDouble ( value1 . Text ) ;
32
+ double second = Convert . ToDouble ( value2 . Text ) ;
33
+ resultBox . Text = Convert . ToString ( first + second ) ;
34
+ }
35
+ catch ( Exception ex )
36
+ {
37
+ resultBox . Text = "Error: Please input only numerical values" ;
38
+ }
39
+ }
25
40
}
26
41
27
42
private void subractButton_Click ( object sender , EventArgs e )
28
43
{
29
- double first = Convert . ToDouble ( value1 . Text ) ;
30
- double second = Convert . ToDouble ( value2 . Text ) ;
31
- resultBox . Text = Convert . ToString ( first - second ) ;
44
+ if ( value1 . Text == "" || value2 . Text == "" )
45
+ {
46
+ resultBox . Text = "Error: Please enter two valid values" ;
47
+ }
48
+ else
49
+ {
50
+ try
51
+ {
52
+ double first = Convert . ToDouble ( value1 . Text ) ;
53
+ double second = Convert . ToDouble ( value2 . Text ) ;
54
+ resultBox . Text = Convert . ToString ( first - second ) ;
55
+ }
56
+ catch ( Exception ex )
57
+ {
58
+ resultBox . Text = "Error: Please input only numerical values" ;
59
+ }
60
+ }
32
61
}
33
62
34
63
private void multiplyButton_Click ( object sender , EventArgs e )
35
64
{
36
- double first = Convert . ToDouble ( value1 . Text ) ;
37
- double second = Convert . ToDouble ( value2 . Text ) ;
38
- resultBox . Text = Convert . ToString ( first * second ) ;
65
+ if ( value1 . Text == "" || value2 . Text == "" )
66
+ {
67
+ resultBox . Text = "Error: Please enter two valid values" ;
68
+ }
69
+ else
70
+ {
71
+ try
72
+ {
73
+ double first = Convert . ToDouble ( value1 . Text ) ;
74
+ double second = Convert . ToDouble ( value2 . Text ) ;
75
+ resultBox . Text = Convert . ToString ( first * second ) ;
76
+ }
77
+ catch ( Exception ex )
78
+ {
79
+ resultBox . Text = "Error: Please input only numerical values" ;
80
+ }
81
+ }
39
82
}
40
83
41
84
private void divideButton_Click ( object sender , EventArgs e )
42
85
{
43
- double first = Convert . ToDouble ( value1 . Text ) ;
44
- double second = Convert . ToDouble ( value2 . Text ) ;
45
- resultBox . Text = Convert . ToString ( first / second ) ;
86
+ if ( value1 . Text == "" || value2 . Text == "" )
87
+ {
88
+ resultBox . Text = "Error: Please enter two valid values" ;
89
+ }
90
+ else
91
+ {
92
+ try
93
+ {
94
+ double first = Convert . ToDouble ( value1 . Text ) ;
95
+ double second = Convert . ToDouble ( value2 . Text ) ;
96
+ resultBox . Text = Convert . ToString ( first / second ) ;
97
+ }
98
+ catch ( Exception ex )
99
+ {
100
+ resultBox . Text = "Error: Please input only numerical values" ;
101
+ }
102
+ }
46
103
}
47
104
48
105
private void useResult1_Click ( object sender , EventArgs e )
0 commit comments