0

Can you tell me what is the right answer? I got this problem in sololearn code challenges just now. Answer is count = 4. Right?

https://code.sololearn.com/cJbkum8eVkpc/?ref=app

10th Sep 2022, 3:05 AM
Oliver Pasaribu
Oliver Pasaribu - avatar
4 Answers
+ 1
Oliver Pasaribu Answer is count 4 because odd numbers are 4 between 1 to 9 which are 1, 3, 5, 7 Here (i % 2 == 0) means even number and we are skipping even numbers by using continue. There can be also like this: if (i % 2 != 0) count++; This will also count only odd numbers.
10th Sep 2022, 4:08 AM
AÍąJ
AÍąJ - avatar
0
The code you've provided is pretty messed up, you broke a lot of syntax rules. When including a library in C++ you must add "#" in front of "include" or the compiler won't pay attention to it. Using curly brackets "{" means there must be some kind of indentation. Writing code like a paragraph won't really work. Here i've fixed your code. ------------------------------------------------------------- #include <iostream> using namespace std; int main() { int count = 0; for (int i = 1; i < 9; i++) { if (i % 2 == 0) continue; else count++; } cout << count << endl; return 0; } ------------------------------------------------------------- And yes, the answer is 4.
10th Sep 2022, 3:12 AM
Carbon
Carbon - avatar
0
Yes, shortand version. For demo purpose only. I answered count =4. But sololearn said 4 is not a correct answer.
10th Sep 2022, 3:15 AM
Oliver Pasaribu
Oliver Pasaribu - avatar
0
Depending on the code, yes it produces 4 as an output. Try reading the question again just to make sure you're not forgetting something and if you think there is something wrong with the questions then it's better to report it to the Sololearn team. Try checking the comments / unlocking it with bits.
10th Sep 2022, 3:20 AM
Carbon
Carbon - avatar