Subtract two numbers without - operator

Satyapriyanayak
Posted by Satyapriyanayak under C# category on | Points: 40 | Views : 1262
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Subtract_two_numbers_without_minus
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void btn_Subtract_Click(object sender, EventArgs e)
{
int value1, value2, difference;

if (!int.TryParse(textBox1.Text, out value1))
{
MessageBox.Show("Not a valid integer. Please re-enter.");
textBox1.Focus();
return;
}

if (!int.TryParse(textBox2.Text, out value2))
{
MessageBox.Show("Not a valid integer. Please re-enter.");
textBox2.Focus();
return;
}

difference = value1 + ~value2 + 1;
MessageBox.Show(difference.ToString());
clear();
}
void clear()
{
textBox1.Text = "";
textBox2.Text = "";
}
}
}

Comments or Responses

Login to post response