# Making a number to decimal form

1. Sep 29, 2008

### soul5

I'm doing an excerise to make factions, but I need to simulate a \frac{}{}
command. To display numbers in faction AND decimal form. How do I simulate a
\frac{}{} command? Thanks. Like I have to prompt the user.

Code (Text):
int denominator, numerator;
scanf("\\frac{%d}{%d}", &numerator, &denominator);
cout << numerator << " / " << denominator;

Enter fraction in the form n1/n2:
1
\frac{1}{2} is --
2

or 0.5

how do I make it to decimal?

2. Sep 29, 2008

### zyh

Hi, I think the "scanf" statement is too complex, I just rewrite your code:
Code (Text):
int main(int argc, char* argv[])
{
int denominator, numerator;
scanf("%d,%d", &numerator, &denominator);
printf("%d / %d \n",numerator,denominator);

}
What does "simulate a \frac{}{} command " means? C treat any number is decimal base by default.

3. Sep 29, 2008

### Staff: Mentor

When you write decimal, do you mean float?

4. Sep 29, 2008

### soul5

Here is what the excerise says

One such command displays fractions. For example 5/4 is entered
"\frac{5}{4}". Write a computer program that simulates a \frac{}{}
command. The program reads two integers n1 and n2

EXAMPLE 1:
Enter fraction in the form n1/n2: 5/4
.................... 5
\frac{5}{4} is --
................... 4

.... . 1
or 1 --
.... . 4

or 1.25

5. Sep 30, 2008

### Staff: Mentor

1.25 is just float to me.

6. Sep 30, 2008

### rcgldr

Some calculators have a fraction feature that will maintain numbers as integer fractions (within reason). My guess is that the goal here is create the equivalent of this with a C program, then have another feature to convert the fraction back to a float or double.

7. Sep 30, 2008

### zyh

I still don't understand the OP's question...

8. Sep 30, 2008

### Staff: Mentor

I think it is just about simulating LaTeX \frac output in ASCII.