Created
May 2, 2010 21:05
-
-
Save tonetheman/387454 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <cstring> | |
using std::cout; | |
using std::endl; | |
// convert string to double old school | |
double convert(char * s) { | |
int i=0; | |
double intPart = 0, fracPart = 0; | |
while(s[i]!='.') { | |
intPart = intPart*10 + (s[i]-'0'); | |
i++; | |
} | |
i = strlen(s)-1; | |
while(s[i]!='.') { | |
fracPart = (fracPart + (s[i]-'0'))/10; | |
i--; | |
} | |
double conversion = intPart + fracPart; | |
return conversion; | |
} | |
int main() { | |
cout << convert("3.14159") << endl; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment