Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Fails to output correct per step in numeric range

I don’t know, how, can I get this to work, so that, depending on the step, it gives me correct output and amount. I know, 1000 / 10 = 100, but, it cannot start over from 100 after 900. What if, 1000 / 2.5 or something, depending on context.

C# code:

using System;
                    
public class Program
{
    public static void Main()
    {
        int m_step = 10;
        int m_maximum = 1000;
        int m_minimum = 0;
        var factor = 1000 / (m_maximum - m_minimum);
        
        for(var i = m_minimum; i < m_maximum; i++){
            if(!(i % m_step == 0))
                continue;
            int v = ((m_maximum - i) * factor);
            System.Console.WriteLine(@"{0}", v);
        }
    }
}

Current output:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

1000
990
980
970
960
950
940
930
920
910
900
890
880
870
860
850
840
830
820
810
800
790
780
770
760
750
740
730
720
710
700
690
680
670
660
650
640
630
620
610
600
590
580
570
560
550
540
530
520
510
500
490
480
470
460
450
440
430
420
410
400
390
380
370
360
350
340
330
320
310
300
290
280
270
260
250
240
230
220
210
200
190
180
170
160
150
140
130
120
110
100
90
80
70
60
50
40
30
20
10

Desired output:

1000
900
800
700
600
500
400
300
200
100

>Solution :

Based on your comment, your code simply doesn’t reflect what you are looking for, try this

int m_stepCount = 10;
int m_maximum = 1000;
int m_minimum = 0;
int m_stepSize = (m_maximum - m_minimum) / m_stepCount;

for(var i = m_stepCount; i > 0; i--)
{
    int v = i * m_stepSize;
    System.Console.WriteLine(@"{0}", v);
}

eg.
https://dotnetfiddle.net/KmmYPC

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading