1. ## Expressions

Code:
```l have to create a C program in which you can enter expressions to be evaluated.

Here are the instructions:

The operands in the expression are floating-point numbers; the operators are +, -, *, and /. The expression is evaluated from left to right (no operator takes precedence over any other operator).

Specifications:
a)	You can assume that the expression has the format: an operand followed by an operator, then by an operand, an operator, …, ended with an operand.
b)	Use float type for the operands and the value of expressions.
c)	If there is a dividing by zero in the expression, display “Cannot divide by zero” error message and abort the program.
d)	Skip blank characters in an expression.

Is there another way I can create the loop without requesting input of 0?

This is the expected output:

Enter an expression: 1+2.5*3
Value of expression: 10.5

This is what I get.

Enter an expression: 1+2.5*3
0
The value of expression is: 10.5

Can anyone help me to figure this out?

Here is what I have.

#include <stdio.h>
int main(void)
{
char ch;
float n, value = 0;
printf("Enter an expression: ");

scanf("%f%c%f", &value, &ch, &n);
if (n == 0)
{
printf ("ERROR!! Cannot divide by zero.\n");
return 0;
}

while (n != 0) {
if (ch == '+')
{
value += n;
}
if (ch == '-')
{
value -= n;
}
if (ch == '*')
{
value *= n;
}
if (ch == '/')
{
value /= n;
}

scanf("%c%f", &ch, &n);
}
printf("The value of expression is: %.1f\n", value);
return 0;
}```

2. If your while loop is (n!=0) then yeah you're going to have to input a zero. The answer is, don't do that. Make your while loop look at your scanf (since that's what's reading the input) -- even better just read in one line, then use sscanf to read from that string until the string is exhausted.

3. You did get some replies in the previous thread you started. If you decided that it should be C rather than C++, then it would have been better to post in your existing thread that you want it moved - the moderators are able to do that.

C++ Program to evaluate expressions

--
Mats