So i'm trying to recursively create a function that takes a string such as "1234" and return it as an integer such as 1234. I can not use any libraries or the such for this assignment. I have it sort of working however when I test for "36" I get 20 back instead and I am completely stuck on it
#include <iostream>
#include <math.h>
//-->>>>>
//--> it checks for aeiou, returns false for reverse, does not recognize it with other
//--> letters though
//-->>>>>>>>>>>>
int str2int(const char *mystr){
int len = 0;
int sum = 0;
int negative = 0;
if(mystr[0] == '\0'){
return 0;
}
for(int i = 0; mystr[i]; i ++){
len++;
std::cout<<len<<std::endl;
}
int i = 0;
if(mystr[i] < 48 || mystr[i] > 58){
return 0;
} else{
//sum = sum*10;
return (mystr[0] - 48) + pow(10,(len-1)) + str2int(mystr + 1);
}
I believe I found my error that say if I put 20 in, I get the two back but it is not returning the 0, I am currently trying to see how I can get the zero but I am also stuck on that as well