Thread: Calculator Help

  1. #1
    Registered User
    Join Date
    Nov 2011
    Posts
    19

    Calculator Help

    Write a program to model a simple calculator. Each data line should consist of the next operation to be performed from the list below and the right operand. Assume the left operand is the accumulator value (with an initial value of 0). You need a function scan_data() with two output parameters that returns the operator and the right operand scanned from the data line. You need a function do_next_op() that performs the required operation. do_next_op() has two input parameters (the operator and the operand) and one input/out put parameters ( the accumulator). The valid operators are:

    + add
    - minus
    * multiply
    / divide
    ^ power(raise left operand to power of right operand)
    q quit

    Your calculator should display the accumulator value after each operation.

    Sample run:

    Calculator program ( RESULT=0)

    Input: + 5.0
    Result:5.0

    Input: ^ 2
    Result:25.0

    Input: / 2
    Result:12.5

    Input: q
    Final Result:12.5


    I don't know how to make it..can any one help?? or a clue??

  2. #2
    Registered User
    Join Date
    Dec 2011
    Posts
    795
    I'm surprised this guy got the font formatting right after clearly copy-pasting a homework assignment.

    Seriously, try it yourself, and if you have trouble, post specifically what your problem is.

  3. #3
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,318
    I don't understand how some people do not understand how incredibly rude it is to start a post with an imperative i.e. "Write a program to ...".
    If the first thing I read commands me to do something then my immediate reaction is that the person can <insert colourful phrase here>.

    Yes upon reading further, I know these instructions must be meant for you, that doesn't excuse you though, not by a long shot. Just for that, I'm not going to help, yet.
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    My reaction is to say
    Read this -> Announcements - C Programming

    And then close it.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. CRC Calculator Help
    By Dukefrukem in forum C Programming
    Replies: 2
    Last Post: 09-21-2007, 02:56 PM
  2. Calculator
    By SilkeyWurzt in forum C++ Programming
    Replies: 11
    Last Post: 07-27-2007, 01:47 AM
  3. Calculator
    By Scarvenger in forum C++ Programming
    Replies: 3
    Last Post: 10-24-2005, 03:39 PM
  4. Calculator in C?
    By daveS in forum C Programming
    Replies: 5
    Last Post: 08-04-2003, 10:37 AM
  5. Need help in RPN calculator
    By Lost__Soul in forum C Programming
    Replies: 14
    Last Post: 05-29-2003, 02:01 PM