-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathHelperFns.cs
142 lines (106 loc) · 3.47 KB
/
HelperFns.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace EnigmaApp_v2
{
public class HelperFns
{
public static void MessageBoxOK(string message, string caption)
{
MessageBoxButtons buttons = MessageBoxButtons.OK;
DialogResult result;
// Displays the MessageBox.
result = MessageBox.Show(message, caption, buttons);
}
public static void MessageBoxYesNo(string message, string caption)
{
MessageBoxButtons buttons = MessageBoxButtons.YesNo;
DialogResult result;
// Displays the MessageBox.
result = MessageBox.Show(message, caption, buttons);
}
public static int RandInt(int min, int max)
{
Random randGen = new Random();
int randInt = 0;
randInt = randGen.Next(min, max);
return randInt;
}
// function to check if a number is a prime
public static bool PrimeCheck(int posPrime)
{
// initialize local variables
bool bCheck = false; // always return false unless proven otherwise, covers the 1 and 0 case
int iPCheck = posPrime;
// loop over the number, counting down till 2
while (iPCheck > 1)
{
// check for remainder and decrement if there is a remainder
if ((posPrime != 1) && (posPrime != 0) && (iPCheck != 2) &&((posPrime % (iPCheck - 1)) != 0))
{
iPCheck--;
}
// else if no remainder, then the number is divisible
else if ((posPrime != 1) && (posPrime != 0) && (iPCheck != 2) && ((posPrime % (iPCheck - 1)) == 0))
{
bCheck = false;
break;
}
// 2 is always a prime
else if (iPCheck == 2)
{
bCheck = true;
break;
}
}
return bCheck;
}
//checks if a certain string can be converted to an int
public static bool stiInputCheck(string s)
{
bool noException = true;
try
{
Convert.ToInt32(s);
}
catch (FormatException)
{
noException = false;
}
catch (OverflowException)
{
noException = false;
}
return noException;
}
public static double DTR(double degrees)
{
double rad = (double)(degrees * (Math.PI / 180.0));
return rad;
}
public static double RTD(double radians)
{
double deg = (double)(radians * (180 / Math.PI));
return deg;
}
public static double RootXY(double root, double radicand)
{
double result = 0;
result = Math.Pow(radicand, (1 / root));
return result;
}
public static double Factorial(double n)
{
double result = n;
double counter = (n - 1);
while (counter > 1)
{
result = result * counter;
counter--;
}
return result;
}
}
}