howdy,
this is what im trying to do:
given this type of input - 25'-5.5" (how ever this input may contain less 3'-6" or more 125'-5.75" characters)
i want to
remove all none digit characters
multiply the figure before the dash by 12 - in this case 25 * 12
add it to the figure after the dash - in this case 5.5
so the answer in this case would be 305.5
with this code i get as far as this:
i can strip the non didgit stuff so i get 25 5.5
i can atof the first figure and multiply it by 12 so i get x=300
what i cant figure out is how to isolate the 5.5 so i can atof it - so now y always equals zero.
this is where im at-------
all i really want is a concept of how to do it - im trying to learn this stuff so someone else writing the code might not be as good of lesson.Code:#include <stdlib.h> #include <iostream> #include <string.h> #include <ctype.h> using namespace std; int main() { double x=0; double y=0; int j=0; system("clear"); char input[20]; cout<<"Enter dimension: "; cin>>input; cout<<"Your dimension is: "<<input<<endl; for(int i = 0; i<strlen(input); i++) if(input[i]=='-' || input[i]=='\''|| input[i]=='"'){ cout<<"Found it @: "<<i<<" position\n"; input[i]= ' '; } cout<<"\nAfter processing input = "<<input<<"\n"; x=atof(input); cout<<strlen(input)<<endl; cout<<"X = "<<x * 12<<" inches"<<endl; cout<<"Y = "<<(y)<<endl; return 0; }