K
K
kevus2018-08-09 22:19:38
C++ / C#
kevus, 2018-08-09 22:19:38

Calculate % at different numbers (C#)?

Hello. There is this code:

double value = Convert.ToDouble(s);
double onePercent = value / 100;
value = value + onePercent * 10;
return value.ToString();

value = number + 10%.
How to make that, depending on the sum of the number, a unique% is added?
For example:
200 + 30%
600 + 25%
1000 + 20%
1400 + 15%
2000 + 10%

Answer the question

In order to leave comments, you need to log in

4 answer(s)
O
Oleg Pogrebnyak, 2018-08-09
@S0HardCore

int arrayA[] = new int[5] { 200, 600, 1000, 1400, 2000 };
double arrayB[] = new double[5] { .3, .25, .2, .15, .1 };


for (int a = 0; a < arrayA.Length; ++a)
if (value == arrayA[a])
{
value += value * arrayB[a];
break;
}

spoiler
Да, можно было бы использовать словарь, но для новичка и два массива подойдут.

D
Denis Melnikov, 2018-08-09
@Mi11er

if, case ...
Explain the essence of the task, otherwise in the description it is not very clear what you want. What kind of condition, how should it be considered.

G
Griboks, 2018-08-09
@Griboks

Do you need to add 10 percent to the number?
(Convert.ToDouble(s)*1.1).ToString()

R
Roman, 2018-08-10
@yarosroman

Random to the rescue

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question