Quang Dinh Luong

Quang Dinh Luong

  • NA
  • 76
  • 17.7k

Errors in Apps Checking Prime Number

Oct 6 2015 11:06 PM
 This is how my program looks like, sorry for bad arrangement
I get this error: Cannot implicity convert type "string" to "int"
Anyone knows how to fix it? Your help'll be very appriciated
 
 
namespace IsThisPrime
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
int x = textBox1.Text;
int i = 0;
bool Flag = false;
for (i = 2; i <= x / 2; i++)
{
if ((i == x))
i = i + 1;
if ((x % i == 0))
{
Flag = true;
break;
}
}
if ((Flag == false))
{
// this num is prime number
MessageBox.Show("PRIME");
}
else
{
// this num is not prime number
MessageBox.Show("NOT PRIME");
}
 

Answers (12)