Question

Hello I keep getting this error Case value is not a constant expression for a lot...

Hello

I keep getting this error Case value is not a constant expression for a lot of my cases like the one case(operand(expire[I])) Am I not supposed to do a function call in the case? Thank you.

for (int i=0; i<expr.length(); i++)

{

  switch(expr[i])

{

  case (operand(expr[i])):

valStack.push(expr[i]);

  break;

  case expr[i]=='(':

opStack.push(expr[i]);

  case opera(expr[i]):

  if (opStack.empty())

opStack.push(expr[i]);

  else if (precedence(expr[i])>precedence(opStack.top()))

opStack.push(expr[i]);

  else

{

  while (!opStack.empty() && precedence(expr[i]<=precedence(opStack.top())))

execute(valStack, opStack);

   opStack.push(expr[i]);

}

  break;

  case expr[i]==')':

  while (opStack.top()!='(')

{

execute(valStack, opStack);

result=valStack.top();

}

  

}

}

  return 0;

} // end processExpression

0 0
Add a comment Improve this question Transcribed image text
Answer #1

First thing you have to know is compiler needs the expression to be known at compile time to compile a switch and yes are obviously right, you are not supposed to do function call in case statement because the return value of the function is not known at compile time.

So the solution for this is simple: Convert the switch statement into an if-else statement.

Add a comment
Know the answer?
Add Answer to:
Hello I keep getting this error Case value is not a constant expression for a lot...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • I need assistance with this code. Is there any way I can create this stack class (dealing with infix to postfix then postfix evaluation) without utilizing <stdio.h> and <math.h>? ________...

    I need assistance with this code. Is there any way I can create this stack class (dealing with infix to postfix then postfix evaluation) without utilizing <stdio.h> and <math.h>? ____________________________________________________________________________________________ C++ Program: #include <iostream> #include <string> #include <stdio.h> #include <math.h> using namespace std; //Stack class class STACK { private: char *str; int N; public: //Constructor STACK(int maxN) { str = new char[maxN]; N = -1; } //Function that checks for empty int empty() { return (N == -1); } //Push...

  • C++ Code error help. I am getting the error: "expression must have a constant value, the...

    C++ Code error help. I am getting the error: "expression must have a constant value, the value of parameter 'n' ( declared at line 7) cannot be used as a constant" I am also getting this error at lines 65 and 66 with m and n. I do not know how to fix this. Here is my code and ive marked where the errors were with lines: #include<iostream> using namespace std; // Function to allocate memory to blocks as per...

  • Can someone help me solve this problem? Everything works but I keep getting an error "expression...

    Can someone help me solve this problem? Everything works but I keep getting an error "expression must have a constant value". Its the Extended Euclidean Algorithm #include <iostream> using namespace std; #include<vector> void TwoLargest(int a[], int x) {    int largeOne = a[0];    int largeTwo = a[0];    for (int i = 1; i < x; i++)    {        if (a[i] > largeOne)        {            largeTwo = largeOne;            largeOne =...

  • I keep getting this error and I do not know how to fix it. this is...

    I keep getting this error and I do not know how to fix it. this is the code I've been working on: please help me import java.util.*; public class TelephoneNumber { public static void main(String[] args) {String number; int i=0,j=0; char c; Scanner in=new Scanner (System.in); System.out.println("Enter the phone number: "); number=in.nextLine(); number=number.toUpperCase(); c=number.charAt(i); while(c!='\n'&&j<=7) {switch(c) {case 'A': case 'B': case 'C': System.out.print("2"); j++; break; case 'D': case 'E': case 'F': System.out.print("3"); j++; break; case 'G': case 'H': case'I': System.out.print("4");...

  • Hello, please correct the following C++ CODE it is not working on visual studio: (I WILL RATE, NO...

    Hello, please correct the following C++ CODE it is not working on visual studio: (I WILL RATE, NO INCOMPLETE OR WRONG SOLUTIONS PLEASE) // CPP program to evaluate a given // expression where tokens are // separated by space. #include using namespace std; // Function to find precedence of // operators. int precedence(char op){ if(op == '+'||op == '-') return 1; if(op == '*'||op == '/') return 2; return 0; } // Function to perform arithmetic operations. int applyOp(int a,...

  • Help me to fix this code in C language. This code converts infix expressions to postfix and then evaluate the expression...

    Help me to fix this code in C language. This code converts infix expressions to postfix and then evaluate the expression. Right now, it works with single digits. I need to modify it so that it can evaluate expressions with also 2 digits, example: (60+82)%72. Additionally I need to display an error when the parenthesis don't match like (89+8(. I have muted some line that would print the postfix expression with a space like: 22 8 + when the input...

  • This is what I have so far. I'm getting an error on the ... case 3:...

    This is what I have so far. I'm getting an error on the ... case 3: System.out.println("Enter the rank of the card you want removed"); cards.remove(); System.out.println(); break; -------------------------------------- package PlayingCards; import java.util.Scanner; public class Driver { public static void main(String[] args) { Scanner sc = new Scanner(System.in); boolean done = false; int menuInput; DeckOfCards cards = new DeckOfCards(); do { System.out.println("Enter the number of one of the choices below:"); System.out.println("1: Shuffle The Deck."); System.out.println("2: Print The Cards Remaining In...

  • Currently, I'm getting this as my output: "Exception in thread "main" java.lang.NullPointerException    at InfixExpression.execute(InfixExpression.java:98)   ...

    Currently, I'm getting this as my output: "Exception in thread "main" java.lang.NullPointerException    at InfixExpression.execute(InfixExpression.java:98)    at InfixExpression.Evaluate(InfixExpression.java:65)    at InfixExpression.setWholeExpr(InfixExpression.java:24)    at InfixExpression.<init>(InfixExpression.java:17)    at Main.testHW1(Main.java:17)    at Main.main(Main.java:6)" I need to get this as my output: "Testing InfixExpression: When passing null, the String and double = Infix String: , result: 0.0 When passing a valid String, the String and double = Infix String: ( 234.5 * ( 5.6 + 7.0 ) ) / 100.2, result: 29.488023952095805 ..." I...

  • Can someone help with this C++ code. I am trying to compile and I keep running...

    Can someone help with this C++ code. I am trying to compile and I keep running into these 4 errors. #include <iostream> #include <cassert> #include <string> using namespace std; typedef int fsm_state; typedef char fsm_input; bool is_final_state(fsm_state state) { return (state == 3) ? true : false; } fsm_state get_start_state(void) { return 0; } fsm_state move(fsm_state state, fsm_input input) { // our alphabet includes only 'a' and 'b' if (input != 'a' && input != 'b') assert(0); switch (state) {...

  • I am currently doing homework for my java class and i am getting an error in...

    I am currently doing homework for my java class and i am getting an error in my code. import java.util.Scanner; import java.util.Random; public class contact {       public static void main(String[] args) {        Random Rand = new Random();        Scanner sc = new Scanner(System.in);        System.out.println("welcome to the contact application");        System.out.println();               int die1;        int die2;        int Total;               String choice = "y";...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT