Not sure why do I always get a 0 from the isvalidReal function?
int isvalidReal(string signedNum)
{
bool check;
int i = 0, j = 1;
string str = "+-.";
for (i = 0; i <= signedNum.length(); i++)
{
if (isdigit(signedNum[i]))
{
check = 1;
}
else if (signedNum[0] == (str[0] || str[1]) &&
signedNum[1] == isdigit(signedNum[1]))
{
check = 1;
}
else if ((signedNum[i] == str[2]) && j == 1)
{
check = 1;
j = 0;
}
else
{
check = 0;
break;
}
}
return check;
}
int main()
{
string signedNum;
bool check;
cout << "Type a real number with a +/- sign: \n";
cin >> signedNum;
check = isvalidReal(signedNum);
if (check == 1)
cout << "This is a real number" << endl;
else
cout << "This is not a real number" << endl;
char aaaa;
cin >> aaaa;
}