How do I get a program to simplify a fraction, and how do I get a program to recognize if a fraction is a whole number? There is probably a simple solution, but I am oblivious. Thanks alot.
How do I get a program to simplify a fraction, and how do I get a program to recognize if a fraction is a whole number? There is probably a simple solution, but I am oblivious. Thanks alot.
For the whole number thing you could just divide the two numbers and if that is+ 1 then...
Code:no.3 == no.1 / no.2; if (no.3 == 1) { //stuff } else { //stuff }
sorry, but I meant if a number is a whole number
yes if you divide the two numbers in the fraction and they equal one then it is a whole number.
20/20 is a whole number 20/20 = 1
Ah right I might have got you:
if no.1 > no.2
yeah, and 1.2/1.2=1, and 1.2 isn't a whole number
fractions cannot be 1.2 end of
you cannot have 1.2/1.2 it does nto make mathematical sense!
C++ converts fractions to decimal representation and automatically simplifies to lowest term.
Results in .3333333 what is 1/3, not 3/9 (which 1/3 is just the simplified form).Code:cout << 3.0/9.0;
It also automatically recognizes if it is a whole number.
Gives you 2, not 2.0000000Code:cout << 8.0/4.0;
No, you don't understand. I want the program to test if a number is a whole number. it will only accept integers. so if it isn't supposed to output numbers like 1.2, but it can output numbers like 56.
It makes perfect mathmatical sense.you cannot have 1.2/1.2 it does nto make mathematical sense!
1.2 is just 1 and 1/5, or 6/5
6/5 over 6/5 is perfectly legal. Or (6/5) / 9 is perfectly legal.
How do I convert decimals back to fractions?
yes but you cannot have 1.2/1.2
1.2/1.2 == 1/1 == 1
Why not?you cannot have 1.2/1.2 it does nto make mathematical sense!