Please help me with the task: "Sum them all"

Hello, I’m working on this task: Create a class that has one public static method, GetSumBetween, that takes two integers, a and b, and returns as an integer the sum of all integers between a and b (including a and b). In the Main method, read two integers from the console, call GetSumBetween, and print the returned number to the console.
For example (don’t output the green text):

6
10
40 // 6 + 7 + 8 + 9 + 10 = 40

Here is my code:

using System;

namespace Static

{

// Write your code here

class ComeGetSum

{

    public static void GetSumBetween (int a, int b)

    {

        int sum = 0;

        for (int i = a; i <= b; i++)

        {

        sum += i;

        }

    }

}

class SumThemAll

{

    public static void Main()

    {

        int a = int.Parse(Console.ReadLine());

        int b = int.Parse(Console.ReadLine());

        // Write your code here

        Console.WriteLine(ComeGetSum.GetSumBetween);

    }

}

}

Hi, your method GetSumBetween doesn’t return any value, the return type is void. To make this work, you need to change the return type to int and at the end of GetSumBetween - return sum;

alright, thank you! :slight_smile:

1 Like