Hi guys,
I have this C# Question:
1) I have to prompt the user for the number of idioms and write them to a file called "idioms.txt"
I can do this part no problem.
2) Read the lines from "idioms.txt" file and display the number of vowels of each idiom.
Looking at the screenshot of what this should like, I need to show the total of A, total of E, total of I, total of O, total of U.
CODE FOR THE PROMPTING AND WRITING TO FILE (1)
My problem is the second part of the question, I have done (so far) in the second part:
I have tried Googling this, and looking at Stackoverflow, but I only get counting all the vowels (not counting separate vowels).
Thanks
I have this C# Question:
1) I have to prompt the user for the number of idioms and write them to a file called "idioms.txt"
I can do this part no problem.
2) Read the lines from "idioms.txt" file and display the number of vowels of each idiom.
Looking at the screenshot of what this should like, I need to show the total of A, total of E, total of I, total of O, total of U.
CODE FOR THE PROMPTING AND WRITING TO FILE (1)
Code:
int numberOfIdioms;
string fileName = "idioms.txt";
int countA = 0, countE = 0, countI = 0, countO = 0, countU = 0;
Console.Title = "String Functions";
Console.Write("Please enter number of idioms: ");
numberOfIdioms = int.Parse(Console.ReadLine());
string[] idioms = new string[numberOfIdioms];
Console.WriteLine();
for (int aa = 0; aa < idioms.Length; aa++)
{
Console.Write("Enter idiom {0}: ", aa + 1);
idioms[aa] = Console.ReadLine();
}
StreamWriter myIdiomsFile = new StreamWriter(fileName);
for (int a = 0; a < numberOfIdioms; a++)
{
myIdiomsFile.WriteLine("{0}", idioms[a]);
}
myIdiomsFile.Close();
Console.Clear();
My problem is the second part of the question, I have done (so far) in the second part:
Code:
StreamReader readIdiomsFile = new StreamReader(fileName);
while (readIdiomsFile.EndOfStream == false)
{
for (int b = 0; b < idioms.Length; b++)
{
string line = readIdiomsFile.ReadLine().ToUpper();
if (line.Contains("A"))
{
countA++;
}
else if (line.Contains("E"))
{
countE++;
}
else if (line.Contains("I"))
{
countI++;
}
else if (line.Contains("O"))
{
countO++;
}
else if (line.Contains("U"))
{
countU++;
}
I have tried Googling this, and looking at Stackoverflow, but I only get counting all the vowels (not counting separate vowels).
Thanks