c# working with strings practice. | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
- 1

c# working with strings practice.

The problem is as follows: You are creating an authentication system. The password shouldn't contain any of these symbols: char[] notAllowedSymbols = { '!', '#', '

#x27;, '%', '&', '(', ')', '*', ',', '+', '-' }; CS The given program takes the password as input. Task Write a program to output "Invalid", if it contains any disallowed symbols. If the password requirement is satisfied, program shouldn't output anything. Sample Input yl1893!dm$ Sample Output Invalid Hint The message should be output only once regardless of how many disallowed symbols the password contains. and here is my code: using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading; using System.Threading.Tasks; namespace SoloLearn { class Program { static void Main(string[] args) { string password = Console.ReadLine(); char[] notAllowedSymbols = { '!', '#', '
#x27;, '%', '&', '(', ')', '*', ',', '+', '-' }; if (password.Length == 0) { Console.WriteLine("Invalid"); } else for(int i = 0; i < password.Length; i++) { for(int j = 0; j < 11; j++) { if(notAllowedSymbols[j] == password[i]) { Console.WriteLine("Invalid"); break; } } } } } } Here's the kicker, there are 5 test cases, I passed 4/5. I added the if (password.Length == 0) just in case it was being sneaky. the biggest problem really, is that I can't see what word was passed through the test because its locked. anyone pass this and know what I did wrong? Thank you!

9th May 2022, 4:06 AM
Brent Kneeland
Brent Kneeland - avatar
4 Answers
+ 1
Hi guys ,It's work for me using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading; using System.Threading.Tasks; namespace SoloLearn { class Program { static void Main(string[] args) { string password = Console.ReadLine(); char[] notAllowedSymbols = { '!', '#', '
#x27;, '%', '&', '(', ')', '*', ',', '+', '-' }; //your code goes here for(int i= 0;i<notAllowedSymbols.Length;i++) { if(password.Contains(notAllowedSymbols[i])){ Console.WriteLine("Invalid"); break; } else{} } } } }
31st Mar 2023, 12:08 PM
Shadow
0
ignore me please i'm a dummy. the break wasn't sufficient to stop it from printing multiple times. I figured it out.
9th May 2022, 4:13 AM
Brent Kneeland
Brent Kneeland - avatar
0
Awesome that you figured it out yourself! Great job
9th May 2022, 7:49 AM
Ausgrindtube
Ausgrindtube - avatar
0
It's work for me using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading; using System.Threading.Tasks; namespace SoloLearn { class Program { static void Main(string[] args) { string password = Console.ReadLine(); char[] notAllowedSymbols = { '!', '#', '
#x27;, '%', '&', '(', ')', '*', ',', '+', '-' }; if (password.Length == 0) { Console.WriteLine("Invalid"); } else for (int i = 0; i < notAllowedSymbols.Length; i++) { if (password.Contains(notAllowedSymbols[i])) { Console.WriteLine("Invalid"); break; } } } } }
1st Jul 2022, 12:36 PM
ilham niya
ilham niya - avatar