+ 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.
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!
+ 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.
+ 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.



