+ 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 ?

25th Oct 2021, 5:27 PM
Yusuf Razi
Yusuf Razi - avatar
2 Respostas
+ 4
=+ should be += You are redeclaring sum variable. Just remove ‘int’ inside for loop
25th Oct 2021, 5:34 PM
Guillem Padilla
Guillem Padilla - avatar
+ 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
27th Oct 2021, 11:03 AM
sree harsha
sree harsha - avatar