+ 1

While loop in C# ā€œCalculating Rangeā€ challenge

Maybe I’m just tired but I think I’m missing something vital or I’m looking at it all wrong.

12th Feb 2021, 8:27 PM
Benjamin Ian Awumsuri Benjamin Moshi
Benjamin Ian Awumsuri Benjamin Moshi - avatar
3 Answers
+ 7
Arthur , just a hint for you. to get all the numbers upto the limit, you can use: ā–ŖļøŽa loop (while) and a counter variable and run it until limit is reached (counter variable has to be incremented in each loop iteration) while loop needs a valid comparison expression. or ā–ŖļøŽa for loop with a range that defines the limit. no extra counter variable is needed ā–ŖļøŽinside tge loops you can check the currently generated number if its even or not (even numbers can be evenly divided by 2) ā–ŖļøŽif number is even - print it, else use next number to check happy coding and good success!
13th Feb 2021, 12:33 PM
Lothar
Lothar - avatar
+ 6
Arthur , not clear what kind of problem you are encountered. please do a try by yourself, put your code in playground and link it here. thanks this is the task description: Write a program to take N numbers as input and output all even numbers from 1 to N inclusive, each on a new line. so if input is 9, you should generate all numbers up to 9, print them out, each in a separate line, but only numbers that are even. in this case it is 2 4 6 8.
12th Feb 2021, 8:44 PM
Lothar
Lothar - avatar
+ 1
Lothar, yeah I think I understand where i went wrong, so just taking a breather. Once i try it this way and it still fails ill put my code up,... thanks though.
12th Feb 2021, 8:47 PM
Benjamin Ian Awumsuri Benjamin Moshi
Benjamin Ian Awumsuri Benjamin Moshi - avatar