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
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.
Hello I keep getting this error Case value is not a constant expression for a lot...
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...
i am having issues correcting an error in my program here is my code: #include <iostream> // define libraries #include <fstream> using namespace std; // Variable definitions: ifstream infp; // file handler enum Tokens {INT_LIT, IDENT, ASSIGN_OP, ADD_OP, SUB_OP, MUL_OP, DIV_OP, LEFT_PAREN, RIGHT_PAREN, LETTER, DIGIT, UNKNOWN,ENDFILE}; Tokens nextToken; // nextToken read from the file. int charClass; // char class char lexeme [100]; // number of characters per line char nextChar; // next char read from the file int lexLen; //...
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,...
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");...
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 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 =...
Convert infix to postfix, and evaluate postfix using custom Stack created using a singly linked list. This is only supposed to use THAT method, calling a normal Stack will give me a zero. I do have the conversion to postfix, but there may be error in there. But the main problem currently is the evaluation of postfix. I keep getting an error that I made for an empty stack, which I will include. For testing it is only supposed to...
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) {...
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: 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...