calcul total price after discount with smallest price
public static int CalculateTotalPrice(int[] prices, int discount)
{
// Write your code here
// To debug: Console.Error.WriteLine("Debug messages...");
if(discount < 0 || discount > 100 || prices.Length <= 0 || prices.Length >=100){
throw new ArgumentException("invalid input!");
}
double total = 0.0;
Array.Sort(prices);
for (int i = 1; i< prices.Length ; i++){
//Console.WriteLine(prices[i]);
if(prices[i] <= 0 || prices[i] >= 100000){
throw new ArgumentException("invalid price!");
}
total = total + prices[i];
}
double toReturn = total + prices[0] * ((double)(100 - discount)/100);
return (int)toReturn;
}
Aucun commentaire:
Enregistrer un commentaire