Quick C++ cout question

TGCid

Platinum Member
Oct 9, 1999
2,201
0
0
Supposedly a user input 4 into variable x and 2 into y. I would make the program output the result of (x/y). But suppoedly they entered 3 into x and 7 into y. How do I cout it as "3/7" in fraction form rather than decimal?
 

sciencewhiz

Diamond Member
Jun 30, 2000
5,885
8
81
This isn't perfect and I'm not going to post code but here is a simple solution.

check if there is a remainder when you divide x by y

if there is then output variable x "/" variable y

if there isn't a remainder then output the result of x/y

I'm assuming that this is for a class. If it isn't then I'd be happy to post code. I'll try to think of a better solution in the meantime.