Code:`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.

Printable View

- 09-28-2008xbusterxHow do I simulate a program with a \frac{}{} commandCode:
`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.

- 09-28-2008robwhitCode:
`What is a \frac{} command?`

- 09-28-2008twomers
It's latex-speak.

- 09-28-2008tabstop
You don't, at a console. If you're trying for "nice" output like on paper, just write a LaTeX file. If you need to fake it on a screen, print out "2 3/8" or something.

- 09-28-2008xbusterx
- 09-28-2008xbusterx
- 09-28-2008twomers
then do 1/4 in your program.

Code:`#include <iostream>`

int main(){

float frac = 1/4;

std::cout<< frac;

return 0;

}

- 09-28-2008tabstop
- 09-28-2008xbusterx
- 09-28-2008tabstop
- 09-28-2008cyberfish
then explain what you are trying to do?

do you mean you want to parse it?

Code:`int denominator, numerator;`

scanf("\\frac{%d}{%d}", &numerator, &denominator);

cout << numerator << " / " << denominator;

- 09-28-2008xbusterx
- 09-28-2008cyberfish
the output?

the scanf line reads the values into denominator and numerator. - 09-29-2008King Mir
- 09-30-2008xbusterx
Here is what the excerise says

Code:`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