Apparently it makes mathematical sense even to you.1.2/1.2 == 1/1 == 1
Apparently it makes mathematical sense even to you.1.2/1.2 == 1/1 == 1
OK, I'll just explain more clearly what I am asking: what the part of the program in question does is it divides two numbers. Then it is supposed to test whether the quoteint is a whole number. if it is, it displays the whole number, if it isn't, then it is supposed to convert the decimal to a simplified fraction and show me that.
What he was saying was that 1.2/1.2 == 6/5Originally Posted by 7stud
Lets jsut forget I said that...it is late!
Ok, I'll just explain what the program does: first, it divides two numbers. The result is then supposed to be tested. if it is a whole number, then the program displays the number, if it is a fraction, it displays a simplified fraction by converting the decimal to a fraction. so how do I find out if it is a whole number, and how to I make the fraction?
No need. You stated your problem clearly to begin with. Someone get a little untracked in this thread.OK, I'll just explain more clearly what I am asking
To test wether an int is evenly divisible by another int, you can use the modulus or remainder operator(%). If the remainder is 0, then you have a whole number:
Sorry for the last post--it is a double.
how do you use the remainder operator? Sorry, I am new to this.
No one mentioned 6/5 until after you posted that.What he was saying was that 1.2/1.2 == 6/5
Q[How do I convert decimals back to fractions?]q
Boy, that is a complicated answer.
0.25 = ¼
But 0.25 is also 25 100ths, so the decimal form is 25/100 which simplifies to 1/4th.
Which c++ will simplify 1/4th back to 0.25.
See the trouble here?
Uhh….hmmm…good question. Not easily. Maybe someone else knows a smooth trick?
Code:int num1 = 10; int num2 = 3; int remainder = 10 % 3; cout<<remainder<<endl; if(num1 % num2 == 0) cout<<num1<<"/"<<num2<<" is a whole number."<<endl; else cout<<num1<<"/"<<num2<<" is not a whole number."<<endl;
In other words you want it to divide something like let's say, 14/4 and instead of it giving you 3.5, you want 3 1/2.Originally Posted by Victor4015
This is fairly simple if you know how to mathmatically convert the decimal into a fraction.
Do the calculation into a float, then do the same calculation casting the values and placing into an int. Subract the float from the int and put it into the float. You now have your remaining decimal. Multiply that times 100, and cast as an int to knock off the rest of the decimal places. Then put that over 100 and simplify from there.
Sent from my iPad®
Thank you very much, but then how would the program know to simpliy 50/100? Also, what about a fraction like 0.3333333...? I know how to do this mathematically, but how do I do it in the program?
How? Post a detailed list of steps.I know how to do this mathematically
Sent from my iPad®