who can solve this program for me ?
write a program to count the vowels and alphabets in an input line of charachters, Read the charachters one at a time until you encounter the end of line charachter. then print out :
- the number of occurences of each the vowels (a,e,i,o,u) whether capital or small,
- the total number of alphabets, and
- the integer percentage of each vowel.
note that the program should ignore all non-alphabets.
use the switch statement to solve this problem
example:
for the following input:
A good word is a charity
suggested output format is :
Number of vowels:
a 3 ; e 0 ; i 2 ; o 3 ; u 0
Total number of letters is 19
Integer percentage of each vowel :
a 16%; e 0%, i 11% ; o 16% ; u 0%
my Program:
#include <iostream>
#include <string>
using namespace std;
int main()
{
char dummy;
int count, countA, countE, countI, countO, countU, num, length ;
string S1;
char S;
count = 0 ;
countA = 0 ;
countE = 0 ;
countI = 0 ;
countO = 0 ;
countU = 0 ;
num = 0 ;
cout << endl << endl;
cout << " Enter a sentence : ";
getline(cin,S1);
length = S1.length();
while ( num <= length )
{ S = S1.substr(num,1); // ERROR
while ( S >= 'A' || S <= 'Z' || S >= 'a' || S <= 'z')
{
count++ ;
switch (S)
{
case 'a' :
case 'A' : countA++;
break;
case 'e' :
case 'E' : countE++;
break;
case 'i' :
case 'I' : countI++;
break;
case 'o' :
case 'O' : countO++;
break;
case 'u' :
case 'U' : countU++;
}
}
num++;
}
cout << "\n Number of vowels:\n";
cout << " a : " << countA << endl;
cout << " e : " << countE << endl;
cout << " i : " << countI << endl;
cout << " o : " << countO << endl;
cout << " Total number of letters is : " << count << endl;
cout << " Integer Percentage of each vowel : \n";
cout << " a : " << int(countA*100/count) << "%" << endl;
cout << " e : " << int(countE*100/count) << "%" << endl;
cout << " i : " << int(countI*100/count) << "%" << endl;
cout << " o : " << int(countO*100/count) << "%" << endl;
cin >> dummy;
return 0;
}

