What's new
  • Visit Rebornbuddy
  • Visit Panda Profiles
  • Visit LLamamMagic
  • Visit Resources
  • Visit Downloads
  • Visit Portal

[C#] Math Trouble!

Smarter

Member
Joined
Jan 15, 2010
Messages
763
Reaction score
9
I have been running around in circles trying to produce the correct results I can do on paper and on a calculator with C#.

Variables:
bestX = $7.47
bestZ = 80% (0.8)

Example Problem:
7.47 * 2 = 14.94
14.94 * 0.8 = 11.952
14.94 - 11.952 = 2.988 -- [$2.99]!

My issue:
var blah = (-1*((bestX*2)*bestZ) - (bestX*2)); == -17.93

What the hell am I doing wrong? :-\ :confused:
 
I have been running around in circles trying to produce the correct results I can do on paper and on a calculator with C#.

Variables:
bestX = $7.47
bestZ = 80% (0.8)

Example Problem:
7.47 * 2 = 14.94
14.94 * 0.8 = 11.952
14.94 - 11.952 = 2.988 -- [$2.99]!

My issue:
var blah = (-1*((bestX*2)*bestZ) - (bestX*2)); == -17.93

What the hell am I doing wrong? :-\ :confused:
what exactly are you trying to do?
 
First of all, if you want to take 2xbestX and subtract 80% of 2xbestX, you need to reverse your middle equations.

I'm a bit tired, didn't sleep well last night, but this looks right...
(-1*((bestX*2) - ((bestX*2)*bestZ)))

Don't know why you are changing it's sign along with it though (the * -1)

As CnG asked though... what are you trying to do? lol
 
Last edited:
I have been running around in circles trying to produce the correct results I can do on paper and on a calculator with C#.

Variables:
bestX = $7.47
bestZ = 80% (0.8)

Example Problem:
7.47 * 2 = 14.94
14.94 * 0.8 = 11.952
14.94 - 11.952 = 2.988 -- [$2.99]!

My issue:
var blah = (-1*((bestX*2)*bestZ) - (bestX*2)); == -17.93

What the hell am I doing wrong? :-\ :confused:

Depends on what you want to achieve, maybe one of these suggestions may help, incase you want the result to equal 2.988...

1: var blah = Math.Abs(((bestX*2)*bestZ) - (bestX*2));
2: var blah = (bestX*2) - ((bestX*2)*bestZ);
 
Last edited:
Depends on what you want to achieve, maybe one of these suggestions may help, incase you want the result to equal 2.988...

1: var blah = Math.Abs(((bestX*2)*bestZ) - (bestX*2));
2: var blah = (bestX*2) - ((bestX*2)*bestZ);

That doesn't produce that?
var blah = Math.Abs(((bestX * 2) * bestZ) - (bestX * 2)); = 11.95
 
Last edited:
what the hell u wanna do?

do u want do have -17.93 as result ???
 
Example Problem:
7.47 * 2 = 14.94
14.94 * 0.8 = 11.952
14.94 - 11.952 = 2.988 -- [$2.99]! -- THIS

My issue:
var blah = (-1*((bestX*2)*bestZ) - (bestX*2)); == -17.93 [Not what i'm looking for ^^]
 
what context are we working in? what the hell is this equation being programed into, because we keep asking so we can get a better understanding of whats going on, but you keep throwing that in our faces.
 
PHP:
            var bestX = 7.47;
            var bestY = 0.8;
            var result = Math.Round(bestX * 2 - bestX * 2 * bestY,2);
 
maybe yes ... but that's no math trouble ... absolutely simple
 
Code:
double bestX = 7.47;
double bestY = 0.8;
double result = Math.Round(bestX * 2 - bestX * 2 * bestY, 2);
// result: 2.99
 
Sorry, what it's for is a complicated answer lol. It's a program that calculates me a per unit price and discount percentage to be shown as the lowest and most discounted seller on a website. This portion simply outputs the staged pricing of each batch of units with their discount taken out. However, that SIMPLE math I somehow cannot get to reproduce on my output. So i've been doing it manually :-\.


var bestX = 7.47;
var bestZ = 0.8;
var Blah = Math.Abs((bestX * 2 - bestX * 2 * bestZ)); == 11.952'

....
 
Last edited:
hmm i think i'm missing something...

Which data can u gather from the site?
Do u know the real / vendor price of the "items"? Do u get the Lowest price from the website? What would u now calculate?

or what?
Sorry for the questions, but my english is very poor, and with this explanation i'm missing something to get a real context between your bestX and bestZ ...
What is this bestX in your explanation (bestZ is the discount ... but is bestX now the price with the discount or without?)
 
try this

double bestX = 7.47;
double bestY = 0.8;
double result = (bestX * 2) - (bestY * (bestX * 2));

Example Problem:
7.47 * 2 = 14.94
14.94 * 0.8 = 11.952
14.94 - 11.952 = 2.988 -- [$2.99]!

 
Last edited:
Okay, in-depth here we go. BestX is the Best Possible Price Per Unit, after it has already calculated such, and bestZ is the best possible Discount percentage to assure top discount listing through all unit amounts on the website (a flaw in their website I exploit ;)). What I am trying to do is very simple, take BestX (The Price per Unit), multiply it by a number of units, in this case 2. Then subtract the Discount to show the final price.... it shouldn't be this complicated but no matter what formula I try it keeps giving me the wrong answers... :'(

BestX [7.47] * # Of Units [2] = 14.94
14.94 * BestZ [0.8] = 11.952
14.94 - 11.952 = Discounted Price [2.988]

Code:
var X = 7.47;
var Z = 0.8;
var ans = (X * 2) * (1 - Z); //== 11.952!?!?
var XA = 14.95;
var ZA = 0.8;
var ansA = XA * (1 - ZA); // == 2.99!?!?!?!?

Which should be: Discount price = actualPrice * (1 - discountRate) -- .... BUT WON'T WORK :'(.
 
Last edited:
Okay, in-depth here we go. BestX is the Best Possible Price Per Unit, after it has already calculated such, and bestZ is the best possible Discount percentage to assure top discount listing through all unit amounts on the website (a flaw in their website I exploit ;)). What I am trying to do is very simple, take BestX (The Price per Unit), multiply it by a number of units, in this case 2. Then subtract the Discount to show the final price.... it shouldn't be this complicated but no matter what formula I try it keeps giving me the wrong answers... :'(

BestX [7.47] * # Of Units [2] = 14.94
14.94 * BestZ [0.8] = 11.952
14.94 - 11.952 = Discounted Price [2.988]

Which should be: Discount price = actualPrice * (1 - discountRate) -- .... BUT WON'T WORK :'(.

BestX [7.47] * # Of Units [2] = 14.94
14.94 * BestZ [0.8] = 11.952
14.94 - 11.952 = Discounted Price [2.988]

double bestX = 7.47;
double bestY = 0.8;
int numberOfUnits = 2;
double result = (bestX * numberOfUnits) - (bestY * (bestX * numberOfUnits));

 
Last edited:
BestX [7.47] * # Of Units [2] = 14.94
14.94 * BestZ [0.8] = 11.952
14.94 - 11.952 = Discounted Price [2.988]

double bestX = 7.47;
double
bestY = 0.8;
int numberOfUnits = 2;
double
result = (bestX * numberOfUnits2) - (bestY * (bestX * numberOfUnits));


Do you even try these or do you just post aimlessly? That still equals 11.952.
 
Back
Top