vowel counting error
hey guys i have a problem running this code of vowel counting my code is only reading the first line only can sme1 please help...thanx in advance
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
|
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
void CalculateVowel(string word)
{
//string word;
ifstream infile("input.txt");
int numofA =0;
int numofE =0;
int numofI =0;
int numofO =0;
int numofU =0;
int numofConsonants=0;
int numofSpaces=0;
ofstream outfile("output.txt");
int i=0;
while((!infile.eof())||(i<word.size()))
{
getline(infile,word);
if((word.at(i) =='a')||(word.at(i) =='A'))
{
numofA++;
}
else if((word.at(i) =='e')||(word.at(i) =='E'))
{
numofE++;
}
else if((word.at(i) =='i')||(word.at(i)=='I'))
{
numofI++;
}
else if((word.at(i) =='o')||(word.at(i) =='O'))
{
numofO++;
}
else if((word.at(i) =='u')||(word.at(i)=='U'))
{
numofU++;
}
else if(word.at(i) ==' ')
{
numofSpaces--;
}
else
{
numofConsonants++;
}
}
outfile<<"a "<<numofA<<endl;
outfile<<"e "<<numofE<<endl;
outfile<<"i "<<numofI<<endl;
outfile<<"o "<<numofO<<endl;
outfile<<"u "<<numofU<<endl;
outfile<<"consonants "<<numofConsonants<<endl;
}
int main()
{
string word;
CalculateVowel(word);
return 0;
}
|
you are not incrementing
i
EDIT :
btw, i think the
word parameter in
Calculate() function has no purpose other creating unnecessary temporary variables and using more memory.
It would be better if you will remove
word from the function parameter and just declare it below the function.
1 2 3 4 5 6
|
void CalculateVowel( )
{
string word;
// ...
}
|
Last edited on
Topic archived. No new replies allowed.