Camillia
asked on
Comparing 3 amounts (can't be that hard!)
This can't be that hard but not sure why I can't get it
I have 3 amounts
amount1 = 12.7
amount2 = 33.8
amount3 = 40.99
I want to compare the 3 and find the highest one. How can I do that?? I know one way is use if statement. Not sure how to do this!!
I have 3 amounts
amount1 = 12.7
amount2 = 33.8
amount3 = 40.99
I want to compare the 3 and find the highest one. How can I do that?? I know one way is use if statement. Not sure how to do this!!
u need to add:
using System.Linq;
ASKER
I cant use linq in this app. Is there a way to do it the old fashioned way...using if else, or something similar?
it's easy with 2 values...
if (amount1 > amount2)
whatever;
but not sure how to do it with 3 amounts
it's easy with 2 values...
if (amount1 > amount2)
whatever;
but not sure how to do it with 3 amounts
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
ASKER
yes, Math.Max works. One more question ( i can close this and open a new one, if i need to).
So, now I have the highest, but how can I tell which if-statement it's coming from. So, this is what I have:
So, now I have the highest, but how can I tell which if-statement it's coming from. So, this is what I have:
string paymentMethod = string.Empty;
string method = string.Empty;
if( wahtever) )
{
paymentMethod = "CARD";
amount1 = 55.00;
}
if( whatever2) )
{
paymentMethod = "GIFT";
amoutn2 = 44.33;
}
if( whatever3)
{
paymentMethod = "PAYPAL";
paypalAmount = 37.00
}
double highest = Math.Max(Math.Max(amount1 , amount2 ), amount3 );
//now, I have the highest, how can I set method = paymentMethod which is in this case, it's "CARD"
Open in new window