[x]
Posted via EE Mobile

Search, ask, and monitor your questions on the go with EE Mobile. Visit Experts Exchange from your mobile device and never be out of touch again.

Question
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

9.0

Starting out on C looking for some help with switching

Asked by MrManderson in C Programming Language, Programming Languages

Hello Fellow EE Experts

Im starting out on C with the RPC calculator, Im a vb programmer so doing the program isnt the hard part its doing it in C with the correct syntax :D This is an assignment so I am looking for guidance through this not a direct answer. I have attached a version in VB that I have done however am having a harder time trying to implement in C.

I am going to take the following approach to solve this

1. Read from the command line via argv[]
2. Create an empty stack
3. Go through the command line arguments
4. If operand then add to stack or if operator pop top element from stack and set to temp location
5. Evaluate the top stack with the temp value then pop the stack and then push result
6. Loop through until all have been evaluated.
7. Pop the last remaining value from stack and return result.

So to start off my first question would be how would I implement a switch on the values passed in from command line seeing that the argv is of type string and a switch requires int. How would I do the conversion in C?

Ie.

#include <stdio.h>

int main(int argc, char *argv[])
{
    int x;
    while ( x < argc + 1)
      switch(argv[x])
      {
            case Number:  
                                   /*push to stack*/
            case '+':
                                   /*pop from stack and so on.. */
            default:
            return 0;
        }
}
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
Dim Stack As New ByteStack
 
  Public Sub Main()
    Dim Answer As Double
    Answer = EvaluateRPN("3 2 + 5 *")
    MsgBox "Answer is " & CStr(Answer), vbInformation, "RPN Calc"
    End
  End Sub
 
  Public Function EvaluateRPN(Expression As String) As Double
    Dim i As Integer
    Dim A As Double
    Dim C As Double
    Dim Expn() As String
    Stack.Initialize 128
    Expression = Replace(Expression, "  ", " ")
    Expn() = Split(Expression, " ")
    For i = 0 To UBound(Expn())
      Select Case Expn(i)
        Case "+"
          Stack.POP VarPtr(C), 8
          A = C + A
        Case "-"
          Stack.POP VarPtr(C), 8
          A = C - A
        Case "*"
          Stack.POP VarPtr(C), 8
          A = C * A
        Case "/", "\"
          Stack.POP VarPtr(C), 8
          A = C / A
        Case "^"
          Stack.POP VarPtr(C), 8
          A = C ^ A
        Case Else
          A = Val(Expn(i))
          Stack.PUSH VarPtr(A), 8
      End Select
    Next i
    EvaluateRPN = A
  End Function
[+][-]03/30/08 12:59 PM, ID: 21241744Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]03/30/08 12:59 PM, ID: 21241746Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]03/30/08 01:05 PM, ID: 21241770Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]03/30/08 01:07 PM, ID: 21241780Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]03/30/08 01:31 PM, ID: 21241842Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]03/30/08 01:42 PM, ID: 21241876Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]03/30/08 01:45 PM, ID: 21241886Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]03/30/08 01:47 PM, ID: 21241897Accepted Solution

View this solution now by starting your 30-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

About this solution

Zones: C Programming Language, Programming Languages
Sign Up Now!
Solution Provided By: josgood
Participating Experts: 2
Solution Grade: A
 
[+][-]03/30/08 01:52 PM, ID: 21241908Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20091021-EE-VQP-81 / EE_QW_EXPERT_20070906