Z
Z
Zhenia Bel2021-11-15 20:29:12
C++ / C#
Zhenia Bel, 2021-11-15 20:29:12

How to output 2 variables from a function?

I need to output days and S
Here is my code

public static double While3(double n)
        {
            double S = 0;
            int d = 10,
                sumd = 200,
                days = 1;
            while (S < sumd)
            {
                days++;
                S += d + (d * ( n / 100));
            }
            return days,S;
        }

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vasily Bannikov, 2021-11-15
@defild

Use tuples.

public static (int, double) While3(double n)
        {
            double S = 0;
            int d = 10,
                sumd = 200,
                days = 1;
            while (S < sumd)
            {
                days++;
                S += d + (d * ( n / 100));
            }
            return (days,S);
        }

But I beg you, give normal names to the variables and the function itself.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question