Thread: Calculator v2.2.0

  1. #1
    I am the worst best coder Quantrizi's Avatar
    Join Date
    Mar 2002
    Posts
    644

    Calculator v2.2.0

    Ok, here's v2.2.0. This adds a nifty new thing *the currently location is on the titlebar this time*. To find out all of the bugfixes, knownbugs, new features, please read the "readme.txt" file.

  2. #2
    Registered User red_baron's Avatar
    Join Date
    May 2002
    Posts
    274
    looks cool

    - E] iverse sin

    though it still needs that string input thingy, but i like all the functions, good luck with adding new stuff
    ¿Red Baron?

    "Imagination is more important than knowledge"
    -Albert Einstein (1879-1955)

    Check out my games!

    [code] /* dont forget code tags! */ [/code]

  3. #3
    I am the worst best coder Quantrizi's Avatar
    Join Date
    Mar 2002
    Posts
    644
    Originally posted by red_baron
    looks cool

    - E] iverse sin

    though it still needs that string input thingy, but i like all the functions, good luck with adding new stuff
    Thanks. Never caught that one :-). About the string thing, unless someone can help me, it won't work. I tried using arrays like this:
    Code:
    char symbol[] = { *, /, +, - }
    char symbols[];
    Basically, all it was is this:
    char symbol[] - holds the symbols
    char symbols[] - used for comparison

  4. #4
    Redundantly Redundant RoD's Avatar
    Join Date
    Sep 2002
    Location
    Missouri
    Posts
    6,331
    Good job man, good job.

  5. #5
    Rambling Man
    Join Date
    Jan 2002
    Posts
    1,050
    It should read

    B] Sine since you have cos labeled as cosine and tan labeled as tangent.

    Here are some other suggestions I have. Get rid of all the extra text. Yeah it looks better in some cases but in terms of a calculator I don't think it's needed. Ex. "Enter the angle that you would like to know the sin of" should be "Sin - Enter angle: ". Then have the angle value display as "Sin(angle_value) = sin_value" *angle_value would be the angle value entered and the sin_value would be the calculation of that input*.

    Also, when someone enters 90 for finding the sin you should give an expected value return. You're already checking to see if the number doesn't equal zero, so if you know the value equals zerio just do a manual display for it.
    Ex.
    "Sin - Entger angle: 90"
    "Sin(90) = 0 "

    In a sense it's somewhat pre-dertemined what the output is going to be for when someone enters 90. *Try to do this with as many functions as you can that you would normally not return a value for because it equaled 0*

    Another thing, most people like to find the sin and cos for a number. So you should give the option of the person to enter BC and be able to use the cos and sin function simutaneously, if you understand what I'm saying.

    Include linear and quadtratic functions. Such is have the user enter the y, m, and b values for a linear function and you could tell them the x value or try to do vice versa. For the quadtratic functions you could try to find what the x intercepts are by having the user say what a, b, and c equal. All of these are do-able without using the string line format.

    Other than that your program is coming along nicely. Keep up the good work (hint hint I want to be able to a have a nice fully functional, graphing calculator by the end of the month...j/k).

  6. #6
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    I'm not in the mood to debug this one but take a look at it, when i wrote it I remember it working fine, but I'm too lazy to test it right now...


    Code:
    float Multiply(float a, float b){  return a * b; }
    float Divide(float a, float b){  return (!a || !b) ? 0 : a / b; }
    float Add(float a, float b){ return a + b; }
    float Subtract(float a, float b){ return a - b; }
    
    
    
    float Calculate(char input[], float *runningTotal)
    {
    if(input == NULL || runningTotal == NULL) return 0;
    
    static float initialized = *runningTotal = 0;
    
    bool usingRunningTotal = true;
    
    int max = strlen(input);
    
    float (*functionStack[ max ])(float, float);
    
    float floatStack[ max ];
    
    int iter = 0, funCount = 0, fltCount = 0;
    
    char temp[ max ], *s;
    
    for( s = input; s != NULL;  s++ )
     {
      if(isdigit(*s) || *s == '.')
       {
        usingRunningTotal = false;
        temp[ iter++ ] = *s;
       }
      else
      if(ispunct(*s) || *s == 0)
       {
    
        if( usingRunningTotal )
         {
          usingRunningTotal = false;
          floatStack[ fltCount++ ] = *runningTotal;
         }
        else
         {
          temp[ iter ] = 0;
          floatStack[ fltCount++ ] = atof(temp);
          iter = 0;
         }
    
    
        if(!*s) break;     //...end of input...
    
        switch(*s)
         {
          case '*': functionStack[ funCount++ ] = Multiply;
          break;
          case '/': functionStack[ funCount++ ] = Divide;
          break;
          case '+': functionStack[ funCount++ ] = Add;
          break;
          case '-': functionStack[ funCount++ ] = Subtract;
          break;
         }
       }
     }
    
    if( fltCount != (funCount + 1) ) return *runningTotal;
    
    *runningTotal = floatStack[0];
    
    for(iter = 0; iter < (fltCount - 1); iter++)
     { //...let's do some math...
      *runningTotal = functionStack[ iter ]( *runningTotal, floatStack[ iter+1 ]);
     }
    
    return *runningTotal;
    }
    Code:
    #include <cmath>
    #include <complex>
    bool euler_flip(bool value)
    {
        return std::pow
        (
            std::complex<float>(std::exp(1.0)), 
            std::complex<float>(0, 1) 
            * std::complex<float>(std::atan(1.0)
            *(1 << (value + 2)))
        ).real() < 0;
    }

  7. #7
    I am the worst best coder Quantrizi's Avatar
    Join Date
    Mar 2002
    Posts
    644
    Sebastiani> Ok, thank you. I'll debug it and stuff.

    TechWins> Ok, I'll do that. The other idea about the "Sin (angle) " thing, good idea. I'll change around the stuff to do that. The slope stuff, will have to wait *not to long though*. I was planning on coding that yesterday.

    Ride -or- Die> Thank you. I appreciate that.

    Thanks to all that have replied.

  8. #8
    S Sang-drax's Avatar
    Join Date
    May 2002
    Location
    Göteborg, Sweden
    Posts
    2,072
    Originally posted by Sebastiani
    Code:
    int max = strlen(input);
    
    float (*functionStack[ max ])(float, float);
    This won't work with most compilers, max needs to be a constant.
    Last edited by Sang-drax : Tomorrow at 02:21 AM. Reason: Time travelling

Popular pages Recent additions subscribe to a feed