+ 1
I can't figure out how to do a practice please help 😫
Passing the first level of a video game awards the player 1 point. For each subsequent level passed, the points awarded increment by 1 (2 for the 2nd level, 3 for the 3rd, and so on). The program you are given takes the number of passed levels as input. Complete the given function to take that number as an argument, and recursively calculate and return the total number of points given for all passed levels. Sample Input 3 Sample Output 6 Explanation Level 1: 1 point Level 2: 2 points Level 3: 3 points Total: 1+2+3 = 6 points. https://code.sololearn.com/cQ8SHVXQdiC3/?ref=app
6 Respuestas
+ 1
dark Apprentice
I found 1 too many } & some strange stuff in your code.
I adapted it a bit along the lines of your concept, but this is not a recursive approach
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Sololearn
{
class Program
{
static void Main(string[] args)
{
int levels = Convert.ToInt32(Console.ReadLine());
Console.WriteLine(Points(levels));
}
static int Points(int levels)
{
//your code goes here
int total = 0;
int num = 1;
while(num <= levels)
{
total += num;
num++;
}
return total;
}
}
}
+ 1
Syntax error
+ 1
Thank you
0
Where?
0
What?
- 1
dark Apprentice
Any block not close with curly braces