• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

Quick C++ cout question

TGCid

Platinum Member
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?
 
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.

 
Back
Top