Question: I need help completing this assignment from C#. private void btnCheck_Click(object sender, EventArgs e) { string output = ; int number; bool isPrimeNumber; bool isEvenNumber;
I need help completing this assignment from C#.
private void btnCheck_Click(object sender, EventArgs e) { string output = ""; int number; bool isPrimeNumber; bool isEvenNumber;
if (int.TryParse(txtNumber.Text, out number)) {
// Assigns prime info to output variable output = "Is " + number + " a prime number? " + isPrimeNumber + " ";
// *** Beginning of logic to determine if number is even if (number % 2 == 0) { isEvenNumber =true; } else { isEvenNumber= false; } // *** End of logic for even number
// Build output output += "Is " + number + " an even number? " + isEvenNumber + " ";
// Display output MessageBox.Show(output,"It's All About the Number"); } }
private void IsPrime(int num) { // Determine if num (input value passed to this method's parameter) is a prime number // by checking to see if every number between 2 and one number less divides // into it evenly. If any value does divide evenly, num is NOT a prime number. bool prime = true;
int i = 2; while (i
//private string IsOdd() //{ // string result = ""; // if (num % 2 != 0) // { // result = "Is " + num + " an odd number? True"; // } // else // { // result = "Is " + num + " an odd number? False"; // }
// return result; //}
The method named IsPrime() has a problem. Change its return type so that it accurately indicates the type of data that's being returned. Once the IsPrime() method is corrected, add ONE statement just after the input value is validated in the btnCheck's Click event handler. Call the method IsPrime(), o passing it one argument (the input stored in the variable named number) and o assigning its return value to the local variable named isPrimeNumber. Locate the user-defined method Isodd() and uncomment it. Fix the problem related to its missing parameter, . Once the Isodd() method is corrected, add ONE statement before the MessageBox.Show() statement. Call the method Isodd(), o passing it an argument (the input stored in the variable named number) and o appending its return value to the local variable named output. Locate the decision logic that determines if the input value is an even number. Follow instructions provided in your textbook that will extract this section of code and create a new method, naming it IsEven(). DO NOT extract any code that works with the variable named output. Here are a couple of examples... It's All About the Number X Numbers - Methods X Is 22 a prime numbert False Is 22 an even number? True is 22 an odd numbert False Enter a number 22 Check OK
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
