#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2012
    Posts
    1
    Rep Power
    0

    Stuck on problem


    Hello, I am teaching myself programming using Kochan's "Programming in C" book.

    I am stuck on an exercise and was hoping you guys could help me out. Here is the question:

    4. Write a program that acts as a simple “printing” calculator.

    The program should allow the user to type in expressions of the form:

    number operator

    The following operators should be recognized by the program:

    + - * / S E

    The S operator tells the program to set the “accumulator” to the typed-in number.

    The E operator tells the program that execution is to end.

    The arithmetic operations
    are performed on the contents of the accumulator with the number that was keyed in acting as the second operand.

    The following is a “sample run” showing how the program should operate:

    Begin Calculations
    10 S //Set Accumulator to 10
    = 10.000000 //Contents of Accumulator
    2 / //Divide by 2
    = 5.000000 //Contents of Accumulator
    55 - //Subtract 55
    -50.000000
    100.25 S //Set Accumulator to 100.25
    = 100.250000
    4 * //Multiply by 4
    = 401.000000
    0 E //End of program
    = 401.000000
    End of Calculations.


    Make certain that the program detects division by zero and also checks for unknown operators.

    Thank you so much for your help guys!
  2. #2
  3. Contributed User
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Jun 2005
    Posts
    4,392
    Rep Power
    1871
    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
  4. #3
  5. Contributing User
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Aug 2011
    Posts
    4,893
    Rep Power
    481
    What is the help you're looking for?

    If you post some code, or also good the outline of an algorithm, or a plan, we can help fill in the details or suggest.

    Cross-posting curtails interest.
    [code]Code tags[/code] are essential for python code and Makefiles!
  6. #4
  7. The bad and the ugly...
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2007
    Location
    Oz... No??? Neverland then?
    Posts
    142
    Rep Power
    0
    Originally Posted by b49P23TIvg
    What is the help you're looking for?

    If you post some code, or also good the outline of an algorithm, or a plan, we can help fill in the details or suggest.

    Cross-posting curtails interest.
    ...you have the most confusing username

    Comments on this post

    • b49P23TIvg agrees : generated by j code ({~ ?@(10&#)@#)AlphaNum_j_ It's nasty, never conflicts, I had to learn it only once.
    "Life is not a journey with the intent on arriving at the finish line in a pretty and well preserved body. But rather to skid in broadside, totally worn out, thoroughly used up and loudly proclaiming, "Wow! What a ride!" -Anonymous
    Halo! || Diablo 2 LOD Modding || OLGA's BACK!

IMN logo majestic logo threadwatch logo seochat tools logo