Difference between revisions of "Testing if a character is in a word"

From TRCCompSci - AQA Computer Science
Jump to: navigation, search
(Created page with " Console.WriteLine("please enter a word:"); string word = Console.ReadLine(); string vowels = "aeiou"; foreach(char c in word) { if(vowels.Contains(c.ToString()...")
 
Line 1: Line 1:
Console.WriteLine("please enter a word:");
+
<syntaxhighlight lang=csharp line>
string word = Console.ReadLine();
+
Console.WriteLine("please enter a word:");
string vowels = "aeiou";
+
string word = Console.ReadLine();
 +
string vowels = "aeiou";
 
 
foreach(char c in word)
+
foreach(char c in word)
{
+
{
if(vowels.Contains(c.ToString()))
+
if(vowels.Contains(c.ToString()))
{
+
{
Console.WriteLine("Vowel found: "+c);
+
Console.WriteLine("Vowel found: "+c);
}
+
}
}
+
}
+
Console.ReadLine();
+
Console.ReadLine();
 +
</syntaxhighlight>

Revision as of 11:41, 15 June 2023

 1 Console.WriteLine("please enter a word:");
 2 string word = Console.ReadLine();
 3 string vowels = "aeiou";
 4 		
 5 foreach(char c in word)
 6 {
 7 	if(vowels.Contains(c.ToString()))
 8 	{
 9 		Console.WriteLine("Vowel found: "+c);
10 	}
11 }
12 	
13 Console.ReadLine();