The purpose of the program is to remove a specific substring from the string, but for some reason it gives me an error when using pow. I don't how I used the function incorrectly, even if it's not the first time I use it. Why doesn't it work?
#include <iostream>
#include <iomanip>
#include <math.h>
usingnamespace std;
void classifyNumber (int, int &, int &);
int main ()
{
bool done;
char k;
int odds;
int evens;
int length;
int num;
done=false;
evens=0;
odds=0;
cout<<"Enter the number of digits you wish to enter: ";
while (!done)
{
cin>>length;
if (length<=0)
{
cout<<"Invalid entry! Please try again";
cout<<"\n";
}
else
{
done=true;
}
}
done=false;
cout<<"\n";
cout <<"Please enter a postive integer: ";
cin>>num;
classifyNumber (num , evens, odds);
cout<<"Enter any character to continue...";
cin>>k;
return 0;
}
void classifyNumber (int number, int &evens, int &odds)
{
int num;
int a;
int b;
int length;
for (int i=length;i>=0;i--)
{
int c;
c=length-i-1;
num=number/(pow(10,c));
b=(num/10)*10;
a=num-b;
if (a==1 || a==3 || a==5 || a==7 || a==9)
{
odds++;
}
if (a==2 || a==4 ||a==6 || a==8)
{
evens++;
}
}
cout<<"There are "<<odds<<" odd and "<<evens<<" even digits";
}