0

ماحل هذه المشكلة؟

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.

10th Jul 2022, 9:19 PM
Zina Shekh Alzoor
Zina Shekh Alzoor - avatar
6 Answers
+ 1
A Code attempt? And little hint for that for(int i = 0; i< ?; i++) ?++;
10th Jul 2022, 9:34 PM
Felix Alcor
Felix Alcor - avatar
+ 1
Zina Shekh Alzoor don't make point++ that was wrong. Make point+=i; because. With point++: 1. Loop: 1 2. Loop: 2 3. Loop: 3 ... With point+=i: 1. Loop: 1 // 1 2. Loop: 3 // 1(First Loop) + 2 3. Loop: 6 // 3 + 3 And make int point= 0. Because you start with 0 Points.
10th Jul 2022, 9:43 PM
Felix Alcor
Felix Alcor - avatar
+ 1
Thx
10th Jul 2022, 9:49 PM
Zina Shekh Alzoor
Zina Shekh Alzoor - avatar
0
static int Points(int levels) { //your code goes here int point=1; for (int i=1;i<=levels;i++) { point++; } return point ; }
10th Jul 2022, 9:37 PM
Zina Shekh Alzoor
Zina Shekh Alzoor - avatar
0
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.
10th Jul 2022, 9:40 PM
Zina Shekh Alzoor
Zina Shekh Alzoor - avatar
0
No Problem 😉
10th Jul 2022, 9:50 PM
Felix Alcor
Felix Alcor - avatar