Having problems with this one as it keeps giving me errors, it is 7.17 in C# ,(V
ID: 3844050 • Letter: H
Question
Having problems with this one as it keeps giving me errors, it is 7.17 in C# ,(Visual C# 2012, How to Program), the Even or Odd program:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Seven
{
// Class definition //
class EvenOrOdd
{
/* Method to find out if the number is an even number @param number is the integer to be checked return true if number is even, false otherwise. */
static bool isEven(int number)
{
// Divide the number by 2 and check if the remainder is 0. If so, return true; false otherwise.
if (number % 2 == 0)
return true;
else
return false;
}
//main()
static void Main(string[] args)
{
// Header message
Console.WriteLine("---------- Even or Odd ----------");
// Variable to store the number
int number;
// Variable to store the value returned by isEven() method
bool check;
// Loop to input values
for (int i = 1; i <= 5; i++);
}
// Prompt the user to input the value
Console.Write("input the number: ");
// Take the value as input
number=Convert.ToInt32(Console.ReadLine());
check=isEven(number);
// Chaeck if method returns true
if(checked==true)
// Display the success message
Console.WriteLine("{0} is an even number", number);
else
// Display the failure message
Console.WriteLine("{0} is not an even number", number);
}
//end loop
Console.Write("Good Bye...");
Console.ReadKey();
//end main()
}
// End Class
}
Thank you for any help and why I am getting error # CS1519
Explanation / Answer
The code you have given above consists of many errors and you will need to make changes according to the program I have listed below and you will have to make the following changes in the program.
EvenOrOdd.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Seven
{
class EvenOrOdd
{
static bool isEven(out int number)
{
string ip = System.Console.ReadLine();
number = 0;
try
{
number = Convert.ToInt32(ip);
return true;
}
catch (System.Exception ex)
{
System.Console.WriteLine("Error in the ip format ");
return false;
}
}
static void Main(string[] args)
{
System.Console.Write("Enter a Number to Check ODD or EVEN: ");
int number = 0;
isEven(out number);
if((number % 2) == 0)
System.Console.WriteLine("{0} is an EVEN number", number);
else
System.Console.WriteLine("{0} is an ODD number", number);
}
}
Please rate the answer if it helps.... Thankyou
Hope it helps...
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.