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.
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.
Last edited by xbusterx; 09-28-2008 at 04:02 PM.
Code:What is a \frac{} command?
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.
then do 1/4 in your program.Code:#include <iostream> int main(){ float frac = 1/4; std::cout<< frac; return 0; }
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;
the output?
the scanf line reads the values into denominator and numerator.
It is too clear and so it is hard to see.
A dunce once searched for fire with a lighted lantern.
Had he known what fire was,
He could have cooked his rice much sooner.
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