![]() |
| | #1 |
| Registered User Join Date: Sep 2006
Posts: 98
| Getting the relationship between two numbers |
| Mavix is offline | |
| | #2 | |
| Mysterious C++ User Join Date: Oct 2007
Posts: 14,783
| Huh? I don't understand what you mean. Especially about "while still holding their relationship to each other". And how to make a number larger or smaller? I'm guessing it's related to the above somehow.
__________________ Using: Microsoft Windows™ 7 Professional (x64), Microsoft Visual Studio™ 2008 Team System I dedicated my life to helping others. This is only a small sample of what they said: "Thanks Elysia. You're a programming master! How the hell do you know every thing?" Quoted... at least once. Quote:
| |
| Elysia is offline | |
| | #3 |
| Registered User Join Date: Sep 2006
Posts: 98
| Lets say, for example, the two numbers, X and Y, are 0.6 and 0.9. If added together they equal 1.5. Now how would I go about lowering both numbers, while keeping their ratio, till they are both equal to 1, or any given number? |
| Mavix is offline | |
| | #4 | |
| Mysterious C++ User Join Date: Oct 2007
Posts: 14,783
| I see. So an equation, huh? Oops. Bad solution.
__________________ Using: Microsoft Windows™ 7 Professional (x64), Microsoft Visual Studio™ 2008 Team System I dedicated my life to helping others. This is only a small sample of what they said: "Thanks Elysia. You're a programming master! How the hell do you know every thing?" Quoted... at least once. Quote:
Last edited by Elysia; 01-29-2008 at 12:42 PM. | |
| Elysia is offline | |
| | #5 | |
| Registered User Join Date: Apr 2007
Posts: 16
| Quote:
Code: float x = 0.6f; float y = 0.9f; float x2 = x / (x + y); float y2 = y / (x + y); | |
| Llam4 is offline | |
| | #6 | |
| Jack of many languages Join Date: Nov 2007 Location: Katy, Texas
Posts: 2,071
| Quote:
You want ratios. .6 + .9 = 1.5, and you want them to add up to 1.0. Read another way, you have .60 and .90 and they add up to 1.50. If we multiply by 100, you have 60% + 90% = 150%, but you want them to add up to 100%. So, figure out what % .6 is of 1.5, and that is 40%. .6 / 1.5 = 40. Checking our math, .9 / 1.5 = 60. 40% + 60% = 100%, so the answer is .4 and .6. Todd Last edited by Dino; 01-29-2008 at 12:25 PM. | |
| Dino is offline | |
| | #7 | |
| Mysterious C++ User Join Date: Oct 2007
Posts: 14,783
| Oops, think I missed the "keep ratios" words there.
__________________ Using: Microsoft Windows™ 7 Professional (x64), Microsoft Visual Studio™ 2008 Team System I dedicated my life to helping others. This is only a small sample of what they said: "Thanks Elysia. You're a programming master! How the hell do you know every thing?" Quoted... at least once. Quote:
| |
| Elysia is offline | |
| | #8 |
| Registered User Join Date: Jan 2008
Posts: 64
| I don't know C#, but in general you want something like this (where limit in your example would be 1.0). Code: convert = limit / (x + y);
x *= convert;
y *= convert;
|
| oogabooga is offline | |
| | #9 |
| Registered User Join Date: Sep 2006
Posts: 98
| Thanks, that worked. It took me a while to figure out that I need absolute values, but I got it working. Once again, thanks! |
| Mavix is offline | |
![]() |
| Thread Tools | |
| Display Modes | |
|
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Logical errors with seach function | Taka | C Programming | 4 | 09-18-2006 05:20 AM |
| display the odd numbers and average the even numbers between two integers | bmilton | C++ Programming | 4 | 03-03-2003 03:52 PM |
| the definition of a mathematical "average" or "mean" | DavidP | A Brief History of Cprogramming.com | 7 | 12-03-2002 11:15 AM |
| Homework help | Jigsaw | C++ Programming | 2 | 03-06-2002 05:56 PM |
| A (complex) question on numbers | Unregistered | C++ Programming | 8 | 02-03-2002 06:38 PM |