Results 1 to 17 of 17

Thread: Arithmetic Operations?

  1. #1

    Thread Starter
    New Member
    Join Date
    Jun 2005
    Posts
    9

    Exclamation Arithmetic Operations?

    I'm currently in Logic, Design, and Programming at college and we have homework over Arithmetic Operations.

    For example:
    100 ^ 2 - (((43 \ 2) + 17) Mod 5 - 7.4) * 3 = 10,013.2

    I need to solve it, we can use VB Express 9 to get the answer but we need to show the work. I've done fine up until the question. We have a test tomorrow and we are have 30/100 points just over math equations where we aren't allowed any use of the PC or calculator and I'm stuck on how to break this down.

    Like this problem I managed fine.
    443 \ 4 * 5 \ 1.25 * 4 \ 12 / 4
    • 443 \ 20 \ 1.25 * 4 \ 12 / 4
    • 443 \ 20 \ 5 \ 12 / 4
    • 443 \ 20 \ 5 \ 3
    • 22 \ 5 \ 3
    • 4 \ 3
    • 1

    OR

    ( 55.7 - 3.7) Mod ( 75 \ 22 + 4 ) ^ 2 + 5
    • 52 Mod ( 3 + 4 ) ^ 2 + 5
    • 52 Mod 7 ^ 2 + 5
    • 52 Mod 49 + 5
    • 3 + 5
    • 8


    My teacher said there is a way to show a debug window and it breaks down the process showing the way VB handles Arithmetic Operations. I can not for the life of my figure this out, I'd even like to write some code to do it for me but the last time I coded was in VB 6 and well, .net has changed everything.

    Help would be GREATLY appreciated!

  2. #2
    PowerPoster
    Join Date
    Apr 2007
    Location
    The Netherlands
    Posts
    5,070

    Re: Arithmetic Operations?

    What is your question?

    Do you need to input an equation (any equation) and let the computer solve it?
    Or do you simply need to write that equation in code, eg
    Code:
    Dim result As Double = 100 ^ 2 - (((43 \ 2) + 17) Mod 5 - 7.4) * 3
    Arithmetic operations in code are mostly exactly like you typed them. Addition (+), subtraction (-), multiplication (*), division( / ), exponentiation (^) and even modulo (Mod) are just the same.

  3. #3

    Thread Starter
    New Member
    Join Date
    Jun 2005
    Posts
    9

    Re: Arithmetic Operations?

    This is how my test problem app ius setup
    Code:
    Option Explicit On
    Option Infer Off
    'Option Strict On
    Public Class Form1
        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            MsgBox(100 ^ 2 - (((43 \ 2) + 17) Mod 5 - 7.4) * 3)
            Me.Close()
        End Sub
    End Class
    I want to type be able to type in an equations such as above and VB break it down for me like this

    I type in somewhere the equation "443 \ 4 * 5 \ 1.25 * 4 \ 12 / 4"
    then VB output the break down and the answer like this
    I want vb to show me the work.

    * 443 \ 20 \ 1.25 * 4 \ 12 / 4
    * 443 \ 20 \ 5 \ 12 / 4
    * 443 \ 20 \ 5 \ 3
    * 22 \ 5 \ 3
    * 4 \ 3
    * 1

  4. #4

    Thread Starter
    New Member
    Join Date
    Jun 2005
    Posts
    9

    Re: Arithmetic Operations?

    It would be nice to have a textbox where I can type it in and the computer solve it instead of manually coding the equation as well.

  5. #5

    Thread Starter
    New Member
    Join Date
    Jun 2005
    Posts
    9

    Re: Arithmetic Operations?

    The reason I ask is because he gives us insane questions that we have to do by hand without a calculator such as

    37 - (( 24 - 5 * 8.2) - (-43)) \ ((19 Mod 11 Mod 3 ) * ( -4 - 7 ))

    I'm stuck and I can't figure out the order of things to solve the problems.

  6. #6
    Discovering Life Siddharth Rout's Avatar
    Join Date
    Feb 2005
    Location
    Mumbai, India
    Posts
    12,001

    Re: Arithmetic Operations?

    Here is something for basic calculations...

    Code:
    Public Class Form1
        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _
        Handles Button1.Click
            Dim Ret As Long = Equate("100*2-((43/2)+17/5-7.4)*3")
        End Sub
    
        Function Equate(ByVal str As String)
            Dim formula As String = "({0})"
            Dim expr As String = String.Format(formula, str)
            Return New DataTable().Compute(expr, "").ToString()
        End Function
    End Class
    A good exercise for the Heart is to bend down and help another up...
    Please Mark your Thread "Resolved", if the query is solved


    MyGear:
    ★ CPU ★ Ryzen 5 5800X
    ★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
    ★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
    ★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
    ★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
    ★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
    ★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
    ★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
    ★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
    ★ Keyboard ★ TVS Electronics Gold Keyboard
    ★ Mouse ★ Logitech G502 Hero

  7. #7

    Thread Starter
    New Member
    Join Date
    Jun 2005
    Posts
    9

    Re: Arithmetic Operations?

    Now how do I get that to display the work or answer? I had it display "Ret" which brought back a 148 which I know is the incorrect answer. I also see datatable but I'm not sure how to store that into an object if I'm reading it correctly. This is my first time using .net. LAst time i touched VB was about 5 years ago and it was VB 6 so my knowledge is VERY rusty, I don't plan on being a programmer but its a part of My CIT/CIS degree.

    I'm sorry if I am becoming frustrating but its been so long and we haven't covered anything more than how to assign variable after 8 week lol.

  8. #8
    PowerPoster
    Join Date
    Apr 2007
    Location
    The Netherlands
    Posts
    5,070

    Re: Arithmetic Operations?

    If you have hardly learned how to assign a variable, then I can't believe your teacher set you an assignment like this. There is only one way you are getting the computer to show the work involved to calculate an equation like that, and it means manually parsing the equation. That is no trivial task. It is doable for the most basic equations (by reading the equation character by character and using the shunting yard algorithm), but that only really works well if you only allow single integer numbers and single-character operators (*, +, -, etc, so no Mod, sin, etc). If you need more flexibility it becomes very difficult really fast.

    I think you misinterpreted your teacher, there is no way he is setting a basic VB class an assignment like this.

  9. #9

    Thread Starter
    New Member
    Join Date
    Jun 2005
    Posts
    9

    Re: Arithmetic Operations?

    He wants us to mentally figure out how to solve the equations and break them down just like a math class and just use like in your example
    Code:
    Dim result As Double = 100 ^ 2 - (((43 \ 2) + 17) Mod 5 - 7.4) * 3
    to check out answer. But some of this problems I can not figure out for the life of me

    He isn't requiring us to create an application to parse a string to do what I'm asking.
    I can't figure out the order of operations for
    Code:
    37 - (( 24 - 5 * 8.2) - (-43)) \ ((19 Mod 11 Mod 3 ) * ( -4 - 7 ))
    Or
    Code:
    4.3 - 1.7 * 2 + ( 240 \ 14 * ( 7 + 9 / 18 ) - 7 )
    Or
    Code:
    37 - (( 24 - 5 * 8.2 ) - ( -43 )) \ (( 19 Mod 11 Mod 3 ) * (-4 - 7 ))
    That's why I was hoping it would be easier in vb express 9 to make that sort of parsing app than it would have been in vb 6

    I've done similar tasks in the past an know it possible but its been SO long ago. I took two years of VB 6 and 1 year of C++ but haven't really used it since so that's why I'm quite rusty.

  10. #10
    Frenzied Member stateofidleness's Avatar
    Join Date
    Jan 2009
    Posts
    1,780

    Re: Arithmetic Operations?

    so what you're saying is this is not a programming question at all and more a math lesson?

    Rule 1: Simplify all operations inside parentheses.
    Rule 2: Simplify all exponents, working from left to right.
    Rule 3: Perform all multiplications and divisions, working from left to right.
    Rule 4: Perform all additions and subtractions, working from left to right.

  11. #11
    PowerPoster cicatrix's Avatar
    Join Date
    Dec 2009
    Location
    Moscow, Russia
    Posts
    3,654

    Re: Arithmetic Operations?

    What discipline is that? Math? Logic? Programming?
    If it's Programming, I think you have misunderstood your teacher.
    Wasn't he talking about Reverse Polish Notation (Or simply Postfix)?

    This is the kind of thing one can hear about at the programming lesson.

  12. #12

    Thread Starter
    New Member
    Join Date
    Jun 2005
    Posts
    9

    Re: Arithmetic Operations?

    We are going chapter by chapter in Visual Basic 2008 Reloaded by Diane Zak. Each week we are given a lab where we have to code a program of the teachers specifications.
    Yes, this is just a math lesson. However, I was wanting to know if parsing was easier in .net than it was in VB6 when I used to program. I wanted to do this not only to get the answer for checking purposes but to also show the work to insure I was doing it correctly.

  13. #13
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    40,104

    Re: Arithmetic Operations?

    Parsing really hasn't changed much. It's still a chore. Figuring out the answer would be one thing. Writing a parser that will also show your work is probably something that will take more effort than the class is worth.
    My usual boring signature: Nothing

  14. #14
    PowerPoster cicatrix's Avatar
    Join Date
    Dec 2009
    Location
    Moscow, Russia
    Posts
    3,654

    Re: Arithmetic Operations?

    Quote Originally Posted by Shaggy Hiker View Post
    Parsing really hasn't changed much. It's still a chore. Figuring out the answer would be one thing. Writing a parser that will also show your work is probably something that will take more effort than the class is worth.
    The most difficult part is tokenization, by the way. It seems easy but in reality it is much more difficult task than the conversion from infix to postfix and further evaluation. After all these algorithms are very well documented and there are many examples. But when I wrote my evaluator, tokenization took the most of the overall time.

  15. #15

    Thread Starter
    New Member
    Join Date
    Jun 2005
    Posts
    9

    Re: Arithmetic Operations?

    Yeah
    He is extremely picky on how we step the process. I have to know which parenthetical to do first then rewrite it with that part finished then find the next, rewrite, etc. its a pain in the ass.

    For example:

    I think this is how to start this problem
    37 - (( 24 - 5 * 8.2 ) - ( -43 )) \ (( 19 Mod 11 Mod 3 ) * (-4 - 7 ))
    • 37 - (( 24 - 41 ) - ( -43 )) \ (( 19 Mod 11 Mod 3 ) * ( -4 - 7 ))
    • 37 - ( -17 - ( -43 )) \ (( 19 Mod 11 Mod 3 ) * ( -4 - 7 ))
    • 37 - ( -17 + 43 ) \ (( 19 Mod 11 Mod 3 ) * ( -4 -7 ))
    • 37 - 26 \ (( 19 Mod 11 Mod 3 ) * ( -4 - 7 ))
    • 37 - 26 \ (( 8 Mod 3 ) * ( -4 - 7 ))
    • 37 - 26 \ 2 * ( -4 - 7 ))
    • 37 - 26 \ ( 2 * -11 )
    • 37 - 26 \ -22
    • 37 - -1
    • 38



    and so on but sometimes i get the wrong answer since i think I'm mentally parsing the parentheticals incorrectly.

    Like for
    4.3 - 1.7 * 2 + ( 240 \ 14 * ( 7 + 9 / 18 ) - 7 )
    I get
    • 4.3 - 1.7 * 2 + ( 240 \ 14 * ( 7 + .5 ) - 7 )
    • 4.3 - 1.7 * 2 + ( 240 \ 14 * 7.5 - 7)
    • 4.3 - 1.7 * 2 + ( 240 \ 105 - 7 )
    • 4.3 - 1.7 * 2 + ( 2 - 7 )
    • 4.3 - 1.7 * 2 + -5
    • 4.3 - 3.4 + -5
    • .9 + -5
    • -4.1

    which is right. Though it took me a while to finish. I still find this too difficult without a calc for a test since I haven't had a math class in 4 years.

    Thanks everyone for the help. I'll mess with an evaluator later on once I get some more under my belt again.
    Last edited by Cyris69; Mar 11th, 2010 at 06:33 PM.

  16. #16
    PowerPoster cicatrix's Avatar
    Join Date
    Dec 2009
    Location
    Moscow, Russia
    Posts
    3,654

    Re: Arithmetic Operations?

    Check this link:

    http://www.chris-j.co.uk/parsing.php

    It shows the evaluation alrorithm step-by-step (you will need Java enabled). I know it's not quite what you were looking for, but maybe you'll find it interesting.

  17. #17

    Thread Starter
    New Member
    Join Date
    Jun 2005
    Posts
    9

    Re: Arithmetic Operations?

    thx cicatrix, I'll look into that and read teh instructions and see how it works. Again thx everyone for the help and quick responses. Maybe by this summer I'll have my own app for this.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width