Making a number to decimal form

  • Thread starter Thread starter soul5
  • Start date Start date
  • Tags Tags
    Form
Click For Summary

Discussion Overview

The discussion revolves around simulating a LaTeX \frac{}{} command in a C program to display fractions in both fractional and decimal forms. Participants explore how to read user input for fractions and convert them to decimal representation.

Discussion Character

  • Technical explanation, Conceptual clarification, Debate/contested, Homework-related

Main Points Raised

  • One participant suggests using "scanf" to read fractions but finds it complex, proposing a simpler input method instead.
  • Another participant questions the meaning of "simulate a \frac{}{} command" and notes that C treats numbers as decimal by default.
  • There is a request for clarification on whether "decimal" refers to float values.
  • A participant mentions the exercise's requirement to read two integers and provide examples of input and output formats.
  • One participant states that 1.25 is simply a float representation.
  • Another participant proposes that the goal is to create a program that maintains integer fractions and can convert them back to float or double.
  • Some participants express confusion regarding the original poster's question and its intent.
  • One participant suggests that the task is about simulating LaTeX \frac output in ASCII format.

Areas of Agreement / Disagreement

Participants do not reach a consensus on the interpretation of the original question or the best approach to simulate the \frac{}{} command. Multiple competing views and uncertainties remain regarding the implementation details.

Contextual Notes

There are unresolved assumptions about the input format and the specific requirements of the exercise. The discussion includes varying interpretations of what it means to simulate the \frac{}{} command.

Who May Find This Useful

Individuals interested in programming in C, particularly those working with fractions and decimal conversions, may find this discussion relevant.

soul5
Messages
63
Reaction score
0
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:
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?
 
Technology news on Phys.org
Hi, I think the "scanf" statement is too complex, I just rewrite your code:
Code:
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.
 
soul5 said:
how do I make it to decimal?

When you write decimal, do you mean float?
 
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
 
1.25 is just float to me.
 
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.
 
I still don't understand the OP's question...
 
I think it is just about simulating LaTeX \frac output in ASCII.
 

Similar threads

Replies
14
Views
4K
  • · Replies 20 ·
Replies
20
Views
2K
  • · Replies 1 ·
Replies
1
Views
1K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 5 ·
Replies
5
Views
2K
Replies
7
Views
2K
Replies
5
Views
3K
  • · Replies 4 ·
Replies
4
Views
3K
  • · Replies 3 ·
Replies
3
Views
4K
  • · Replies 1 ·
Replies
1
Views
2K