So I'm supposed to create a program that will read off words from a .txt file,and use a function to count the number of vowels in each word and then display the specific vowels and their frequencies.
ex. if the word is: butter
the output would be:
a:0
e:1
i:0
o:0
u:1
This is what I have so far, but I'm running into some problems. Any help would be GREATLY appreciated.
Thank you in advance
#include <iostream>
#include <string>
#include <fstream>
using namespace std;
Please state your problems clearly so we can help.
One I see: for(int i=0; i<=str.length(); i++) will lead to exception thrown by .at(). Use: i<str.length().
Second I noticed: your program does count uppercase letters. To solve this, use tolower function before comparing characters. if( tolower(str.at(i)) == //...
I would suggest to use lookup table for this. It will look cleaner, easier to adapt and less error prone.