c++ guide please...

Discussion in 'Programming' started by mubashirnisar, Oct 16, 2009.

  1. #1
    hello Friends,

    I'm making a program and facing a problem in code,
    i want to input an equation , it have characters and integers, mix input in single line .so characters(/,*,-,+) store in character array and integer(1,2,5..etc) stores in integer array from equation,how can i do this step..????

    input:
    4+4*6/6
    output:
    9

    just little guide or hint me i want to make this program myself......
    my English is weak but i hope you'll understand my problem..
     
    mubashirnisar, Oct 16, 2009 IP
  2. organicCyborg

    organicCyborg Peon

    Messages:
    330
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    0
    #2
    I think I understand. You're trying to build a calculator?

    If you take the input into a character array or string, you can step through it using a while loop. Check the ASCII value to see if the current character is a special character or a number, then move to its respective array.

    Once you've done this, you'll need to use a switch statement to actually perform the operations on the numbers.

    Also, is the answer to your example problem supposed to be 8, not 9?
     
    organicCyborg, Oct 16, 2009 IP
  3. mubashirnisar

    mubashirnisar Banned

    Messages:
    2,186
    Likes Received:
    22
    Best Answers:
    0
    Trophy Points:
    0
    #3
    you r right answer is 8.....
     
    mubashirnisar, Oct 16, 2009 IP
  4. Martin

    Martin Peon

    Messages:
    12
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    As long as I understand you are trying to write Reverse Polish Notation Calculator. Here is a description of the algorithm:
    http://en.wikipedia.org/wiki/Reverse_Polish_notation
    And C++ source code:
    http://www.uow.edu.au/~lukes/TEXTBOOK/notes-cpp/examples/rpn/rpn.html
    C# source code:
    http://www.codeproject.com/KB/cs/Reverse_Polish_Notation.aspx
     
    Martin, Oct 17, 2009 IP