Printing fractions in C++ | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Printing fractions in C++

I was wondering how I could print a fraction in C++ on SoloLearn without the compiler doing the math before printing it. When I write in fraction format (lets say 1/2 and 3/8), the compiler does the math and prints the quotient (0.5 and 0.375, respectively). I want to be able to print the fraction, not the quotient of the division problem. Is there any way I could do that on SoloLearn?

31st Jul 2020, 10:12 PM
UnEpic_NotDeveloper
1 Answer
+ 1
The only way to do it (that I know of) is to print it out as a string.
31st Jul 2020, 11:34 PM
Samuel Adepoju
Samuel Adepoju - avatar