1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

C# Calculator

Discussion in 'C#' started by Usmaan, Aug 28, 2010.

  1. Usmaan

    Usmaan Guest

    Hi Folks,

    I'm making a Calculator on Visual Studio (Nope, it's not a College or University assignment).

    I'm at the part where I have added code to all of the number buttons but now need to see how the program is going to calculate sums of x amount of numbers. What I basically mean by that is - I've successfully made the program so that if i type in one number and then press "+" and then type another and then press "Equals" then it will give me the answer. That's dead simple...of course. However, How or what algorithm do i take in to consideration for a scenario where the user not only inputs two numbers but inputs more, for example: 2 + 4 / 4 * 4.... You get the picture.

    This is my pseudo code/abstract/english way of thinking of the possible solution:

    User types something in and hits a specific operator
    System stores that number AND the operator in two different indexes
    Index 0 of the list contains the number and index 1 contains the operator
    do the same for however many times the user wants UNTIL the user presses equals.

    When equals is pressed, get the list, make substrings of that list by chopping and seperating the numbers from the operators. Once that is done, (this is really complicated for me..lol) get the first number, check the operator next to it and do apply that number and the operator to the next number. So if the first number was 1 and the operator next to it was a +, then expect to 1+something. If the number after the operator was, for example .. a number 3 then 1+3, of course. Now do this for the whole list. The list will have a sequence of: number | operator | number | operator | number | operator | number ......... etc.

    Easily said,(well, almost) how would I go about implementing that? :yawn:

    Any help will be...how shall I say, GRATELY appreciated.

Share This Page