Welcome :Guest

Congratulations!!!

Top 5 Contributors of the Month
Melody Anderson

 Home >> Code Snippets >> Visual Studio >> Post New Resource

# Using Simple Maths Expressions Like X+100+20

Posted By:Hefin Dsouza       Posted Date: August 11, 2009    Points: 10    Category: Visual Studio    URL: http://www.dotnetspark.com

## This simple application will take an input from the user in a expression format example "x+200+10? or "x-200-10?

The code works like this
First My Application will check what opperator the expression contains

`````` If s.Contains("+") Then
Dim exp As String = s.Replace("x", x)
Dim nums() As String = exp.Split("+")
Console.WriteLine("Number of Operands are : " & nums.Length)
Dim sum As Integer
For Each x1 As String In nums
Dim num As Integer = x1
sum += num
Next
Console.WriteLine("The Solution for this Expression is : " & sum)
End If

If s.Contains("-") Then
Dim exp As String = s.Replace("x", x)
Dim nums() As String = exp.Trim.Split("-")
Console.WriteLine("Number of Operands are : " & nums.Length)
Dim subs As Integer
For Each x1 As String In nums
Dim num As Integer = x1
subs -= num
Next
Console.WriteLine("The Solution for this Expression is : " & subs)
End If

If s.Contains("*") Then
Dim exp As String = s.Replace("x", x)
Dim nums() As String = exp.Trim.Split("*")
Console.WriteLine("Number of Operands are : " & nums.Length)
Dim mul As Integer
For Each x1 As String In nums
Dim num As Integer = x1
mul *= num
Next
Console.WriteLine("The Solution for this Expression is : " & mul)
End If``````
``` ```

Simple Code You may implement this code to solve big equations.

Regards Hefin Dsouza

Responses

No response found. Be the first to respond this post

Post Comment