0
Please help I am stuck on the c# array practice I think sololearn is broken
The program you are given defines an array with 10 words and takes a letter as input. Write a program to iterate through the array and output words containing the taken letter. If there is no such word, the program should output "No match". Sample Input u Sample Output fun https://code.sololearn.com/cB3xkezay889/?ref=app
5 Respuestas
+ 2
count = count++ doesnt increment the variable at all. So is the case for _count. The line string a = words[count++] doesn't assign the next array element to a because count++ is post increment and while its value does increase, it happens only on the next iteration. So, effectively you're checking the same word throughout the loop. I'd recommend introducing a new variable with false as default value. If you do find a match, just set it to true. Outside the while loop check if it is false, then print no match accordingly.
https://code.sololearn.com/cv9ayB53LCqp/?ref=app
+ 2
The exclamation mark reverses the value of a boolean. For example, !true is false and !false is true. The bool variable found has false value set as default. Now suppose you didn't find a match and the value remains false. So when I check if(!found) it's the same as if(!false) i.e. if(true) thus the if block executes and No match is printed.
The variable count has inital value 0. As you might know, array indices start from 0. I'm storing the array element at count position in the variable a. Only after this is the count variable incremented by 1. Thus, in each iteration, I'm checking the next array element.
Go through the lesson before attempting any end of module projects or practice tasks.
+ 1
Oh ok got it thank you
+ 1
Just ++count;...
0
What does this string word = words[count++]; do that my code doesn't also ive never seen this ! exclamation mark before. Btw thanks I spent all day working on that code lol and you made one that did it in half the lines