+ 3
c# levels question
using System; using System.Collections.Generic; namespace SoloLearn { class Program { static void Main(string[] args) { int levels = Convert.ToInt32(Console.ReadLine()); Console.WriteLine(Points(levels)); } static int Points(int levels) { int sum = 0 ; //your code goes here for(int i=1;i<=levels;i++) { int sum =+ i; }return sum; } } } whats wrong ?
2 Answers
+ 4
=+ should be +=
You are redeclaring sum variable. Just remove âintâ inside for loop
+ 1
the variable sum is duplicating
remove variable declared in the loop and continue with a variable declared outside of the loop and inside of the constructor