VitzzViperzz
Well-known member
Hello,
So I tried making an application that would take in a sentence as a string and then find how many vowels are in that sentence. But it failed.
I tried using the IndexOf function but it couldn't take more than 1 argument - which is rubbish as we have more than a vowel. I then tried passing the number of vowels found to console, but it was pointless.
Here is the code:
Could anyone suggest a better way to do this? and a way that takes more arguments?
Thanks
So I tried making an application that would take in a sentence as a string and then find how many vowels are in that sentence. But it failed.
I tried using the IndexOf function but it couldn't take more than 1 argument - which is rubbish as we have more than a vowel. I then tried passing the number of vowels found to console, but it was pointless.
Here is the code:
C#:
namespace VowelCounter
{
class Program
{
static void Main(string[] args)
{
string userInput;
Console.WriteLine("Enter a string: ");
userInput = Console.ReadLine();
string vowelsToFind = "a";
int index = userInput.IndexOf('a');
Console.WriteLine($"Found {vowelsToFind}, in {userInput}, at position {index}");
Console.ReadKey();
}
}
}
Could anyone suggest a better way to do this? and a way that takes more arguments?
Thanks