# Fraction

• 11-14-2002
Nicknameguy
Fraction
If someone enters 2/3 how do you figure out which is the numerator and the denominator? I know the numerator is 2 and the denominator is 3 but how do you find that out when ur given 2/3?
• 11-14-2002
MrWizard
Read it in as a string, then parse through the string until you reach the / . You know everything until that point will be the numerator. Search after the / to find the denom.
• 11-14-2002
Nicknameguy
okay
that's what i thought u needed to do but how do you search through a string?
• 11-14-2002
golfinguy4
string foo="3/4";
int location;
location=find("/");
• 11-18-2002
Nicknameguy
Fraction Find
Okay I understand that you have to declare whatever the user inputs as a string but what I am confused about is how to find. I have tried your "find" code but it justs messes up everything. It doesn't seem to know what find is. I think it is trying to use "find" as a function but that won't work.

So, let's say I am working on addFraction. I am going to do something similar to this right?

Code:

```cout<<"Enter a fraction: "; string addedFraction; cin>>addedFraction;```
once I finish that I am so confused. I kind of understand why you have to declare an integer to find what is before or after the "/" but I don't know how to write that in C++ Code.

Can you change a character into an integer? I know you can't change a string into a fraction though.

```char input[80]; char temp[80]; int numer; int denom; cout << "enter a fraction like 2/3" << endl; cin >> input; int i; int j = 0; for(i = 0; i < strlen(input); i++) {   if(input[i] == '/')   {     temp[j++] = '\0';     numer = atoi(temp);     j = 0;   }   else   {     temp[j++] = input[i];   } } temp[j] = '\0'; denom = atoi(temp);   cout << numer << '/' << denom << endl;```