# ERROR (expression must have integral or unscoped enum type)

A typical coder faces a lot of errors in the daily life of programming. I think errors are fundamental to programming because by making errors we make our programming fundamentals clear. Sometimes errors can be really messy, they feel nasty even if the cause of error is too small to notice. In this article we will discuss the cause and the solution of the error “expression must have integral or unscoped enum type”.

### Example

``````#include<cmath>

const double PI = 4 * atan(1.0);

double cylinderVolume(double height, double diameter)
{
double cylindervol;

cylindervol = height * PI * (0.5 * diameter) * (0.5 * diameter);

return cylindervol;
}

double tankWallVolume(double height, double diameter, double thickness)
{
double tankwallvol;

tankwallvol = cylinderVolume - (height * PI * (0.5 * diameter - thickness) * (0.5 * diameter - thickness));     //this is the line causing error

return tankwallvol;
}``````

In case you want to research the error in other example then you  can check out the given stackoverflow link. https://stackoverflow.com/questions/21341254/error-expression-must-have-integral-or-unscoped-enum-type

# Cause

As the name suggests, the error is caused due to some variable which should be integer or anything, in the line of error. The program shown above also proves that it (the cause I defined in the previous sentence) is the root and cause of the error. In the example, the cylinder volume is a function not a variable which can be subtracted from the value. So either it should be integral or anything which can be subtracted.

## Solution

For the example given, we can resolve the issue by using the function returned value. Which can be done like this.

``tankwallvol = cylinderVolume( height, diameter ) - ( height * ...``

posted Jun 26 in c++
edited Jun 26