void isEven(std::string op)
{
int number;
std::istringstream iss(op);
int total = 0;
int size = op.length();
int digCount = size;
iss >> number;
for (size_t i = 0; i < size; ++i) {
std::cout << iss.str()[i];
digCount--;
if (iss.str()[i] != '0')
{
total += (iss.str()[i] * pow(2, digCount));
std::cout << "The total is " << total << std::endl;
}
}
}
When I normally output iss.str()[i] on it's own, it's either a 0 or a 1. (as intended). However, when calculating the total it seems to appear that the variable becomes a base value of 49 when [i] should always be 1 in this case. This leads to large, unnecessary totals in my program. I figure it has to do with the data type of total but I am unsure what it needs to be changed to.
> void isEven(std::string op)
i expected for the function to return a boolean
and not sure why you are trying to reconstruct the whole number when you only want to check if it is even.