I'm working on a little hobby project outside of my C++ class where I'm trying to experiment with some ideas we haven't used in class (So it's not homework just to clarify).
I'm basically writing an Ohm's law calculator which prompts the user for the first variable type, and then get the input for that variable. Then it will get the second variable and depending on what kind of variable it is, it will run some logic to use the correct equations.
My code is working as I want it to (as far as I have written it at least), but what I want to do is make some condition where if the value is a "nice" number (as in say just 2, or 30, a "not nice" number would be something like 2.351).
Lets say for instance we have this in my console:
Enter the first known variable (V, I, R, P): I
Enter the current: 0.07186
Enter the second known variable (V, R, P): P
Enter the power: 0.2
Power / Current = Voltage
200.000mW / 71.860mA = 2.783 V
Power / Current^2 = Resistance
200.000mW / 71.860^2 mA = 38.731 Ohms
I want to make it basically so values like 200.000mW print out only as 200mW, or 71.860 will print out as just 71.86mA.
I'm already using:
Is there a way to do what I'm trying to do with a particular command, or is this something I'm going to have to hard code with a situation where rational numbers print out without decimals? (The 71.860 isn't too annoying, it's just a little irritating looking at 200.000mW, it can be misleading at first glance)