# How do I simulate a program with a \frac{}{} command

Show 80 post(s) from this thread on one page
Page 1 of 2 12 Last
• 09-28-2008
xbusterx
How do I simulate a program with a \frac{}{} command
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.
• 09-28-2008
robwhit
Code:

What is a \frac{} command?
• 09-28-2008
twomers
It's latex-speak.
• 09-28-2008
tabstop
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-2008
xbusterx
Quote:

Originally Posted by robwhit
Code:

What is a \frac{} command?

I need to simulate a \frac{}{} command.
• 09-28-2008
xbusterx
Quote:

Originally Posted by tabstop
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.

I don't think you get what I mean like:

Code:

              \frac{1}{4} is -    1/4                                 or                               0.25
• 09-28-2008
twomers
then do 1/4 in your program.
Code:

#include <iostream> int main(){   float frac = 1/4;   std::cout<< frac;   return 0; }
• 09-28-2008
tabstop
Quote:

Originally Posted by xbusterx
I don't think you get what I mean like:

Code:

              \frac{1}{4} is -    1/4                                 or                               0.25

So just print it out. I don't know what kind of spacing you're going for over there on the right, so you'll have to fiddle, but:
Code:

cout << "\\frac{1}{4} is - \t 1/4" << endl << "\t\t\t or" << endl << "\t\t\t 0.25" << endl;
• 09-28-2008
xbusterx
Quote:

Originally Posted by tabstop
So just print it out. I don't know what kind of spacing you're going for over there on the right, so you'll have to fiddle, but:
Code:

cout << "\\frac{1}{4} is - \t 1/4" << endl << "\t\t\t or" << endl << "\t\t\t 0.25" << endl;

lol That wouldn't work though I'm trying to prompt the user not print it obivously I know how to print it all your doing is making stings that's not what I'm trying to do.
• 09-28-2008
tabstop
Quote:

Originally Posted by xbusterx
lol That wouldn't work though I'm trying to prompt the user not print it obivously I know how to print it all your doing is making stings that's not what I'm trying to do.

And where did "prompting the user" come from? If that's what you wanted to do, why didn't you say so the first (or second, or third) time?

What are you stuck on about trying to get input?
• 09-28-2008
cyberfish
then explain what you are trying to do?

do you mean you want to parse it?

Code:

int denominator, numerator; scanf("\\frac{&#37;d}{%d}", &numerator, &denominator); cout << numerator << " / " << denominator;
• 09-28-2008
xbusterx
Quote:

Originally Posted by cyberfish
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;

ok did that but how would I make into decimal form?
• 09-28-2008
cyberfish
the output?

the scanf line reads the values into denominator and numerator.
• 09-29-2008
King Mir
Quote:

Originally Posted by xbusterx
ok did that but how would I make into decimal form?

Code:

cout << double(numerator)/double(denominator);
You have to convert it to double to get it to be treated as a decimal.
• 09-30-2008
xbusterx
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
Show 80 post(s) from this thread on one page
Page 1 of 2 12 Last