Why this program won't run on visualstudio ConsoleApp ? | Sololearn: Learn to code for FREE!

0

Why this program won't run on visualstudio ConsoleApp ?

this program is for question 2 in the"Method" " Optional & Named Arguments " and it don't work on visual studio why ? static int calc(int from, int to, int step = 1) { int res = 0; for (int i = from; i < to; i += step) { res += i; } return res; } static void Main(string[] args) { int res = calc(step: 2, to: 99, from: 5); Console.WriteLine(res); }

4/26/2018 10:36:09 AM

amir ali

3 Answers

New Answer

0

I'm using VS 2017 and I just ran the code without any problems But I don't think VS version is the problem. Your code on VS any version should look something like this: using System; namespace ConsoleApp1 { class Program { static int Calc(int from, int to, int step = 1) { int res = 0; for (int i = from; i < to; i += step) { res += i; } return res; } static void Main(string[] args) { int res = Calc(step: 2, to: 99, from: 5); Console.WriteLine(res); } } }

0

thanks a lot yes your true , i'm forget some code

0

You are welcome Good luck with your coding!