0
Working with Strings
string password = Console.ReadLine(); char[] notAllowedSymbols = { '!', '#', '
#x27;, '%', '&', '(', ')', '*', ',', '+', '-' }; //your code goes here foreach (var item in password) { for (int i = 0; i < notAllowedSymbols.Length; i++) { if (item == notAllowedSymbols[i]) { Console.WriteLine("invalid"); break; } } } here's my code and i can't figure out why it doesn't run on the last test case of the working with strings problem, it works in 4/5 cases6 Réponses
+ 1
The thing is, you have to iterate through the symbols first and only then iterate through the password length.
for(int x=0 ; x<notAllowedSymbols.Length ; x++){
if(password.Contains(notAllowedSymbols[x])){
Console.WriteLine("Invalid");
break;
}
}
0
Please provide the description of this code coach. Also, please don't copy your code into the tags.
0
sorry about that, that was my bad
this is the description; Write a program to take the password as input and output "Invalid", if it contains any disallowed symbols.
If the password requirement is satisfied, program shouldn't output anything.
0
According to the description you provided, unless the program want "Invalid" rather than "invalid", your code looks fine.
If you have modified or shortened the question description, please provide a full one.
0
I haven't shortened it but i could provide the hint; The message should be output only once regardless of how many disallowed symbols the password contains.
My code does this too so i'm not sure what the last test case is testing to fail.
- 1
Try to change "invalid" to "Invalid" in your code then.