Help with why code is returning this way.
Hello, I'm a CS student learning C# for the first time and i'm having some confusion on why my code is returning the way it is. If I input a number and it's a valid number in the array, the program will say it's wrong multiple times before finally printing all of the right data. When I put a
break
on the end of the else
statement, it just says "Sorry, no data for 2020." and then just ends. But if I remove the break
, it says its wrong multiple times before finally printing the expected result. If anyone has any insight into why this is happening, I'd really appreciate it!15 Replies
Well you print it in a loop
Print it after the loop has completed
so i tried to put the Console.WriteLine outside of the loop, but now it doesn't have a reference for the [i] pointer
This one can be inside of the loop
Since you
break
out of it anyway if the condition is metlike that?
inside of the for loop, but outside of the if statement?
No
This line doesn't cause any issues
It gets printed out once, as you want it
It's the other one that causes issues and gets printed multiple times
the
else
statement?
or the yearFound = true;
?That way you also use your
yearFound
variablei tried that already and it gave the same result
You did not try that
i tried it before i posted the question in here
The code you posted now is not doing what I told you to do
So, no, you have not tried what I told you to do
oh yeah, you're right
didn't realize i put it in the for loop, that's probably why it was giving me the same result the last time I tried it. But it seems to be fixed now, thanks for the help!