+ 2

I'm confusing about this!

Complete the expression so that userPoints is assigned with 0 if userLevel is greater than 30 (second branch). Otherwise, userPoints is assigned with 10 (first branch).

17th Feb 2022, 2:23 AM
Altesse
4 Respuestas
+ 6
Altesse Next time, save your code in the code playground and share it's link here so it'll be easy to run it You should assign 0 to user points if user level is > 30. In your if condition, you used userPoints instead is userLevel, so it always assigns 10 to userPoints. Also, your if condition should be userLevel<=30 and not userLevel<30
17th Feb 2022, 2:48 AM
Rishi
Rishi - avatar
+ 3
Ohh yea, thank you!
17th Feb 2022, 2:52 AM
Altesse
+ 2
my code is #include <stdio.h> int main(void) { int userLevel; int userPoints; scanf("%d", &userLevel); // Program will be tested with values: 29, 30, 31, 32. userPoints = 0; if (userPoints < 30) { userPoints = 10; } else { userPoints = 0; } printf("%d\n", userPoints); return 0; }
17th Feb 2022, 2:23 AM
Altesse
+ 1
the first 2 # worked but not the last 2 #
17th Feb 2022, 2:24 AM
Altesse