// header file section #include <iostream> #include<string> #include<stdio.h> us
ID: 3642050 • Letter: #
Question
// header file section#include <iostream>
#include<string>
#include<stdio.h>
using namespace std;
//function prototypes
int Vowel_count(char *str);
int Consonant_count(char *str);
void main()
{
char string[30];
char choice;
int Nvowels,Nconsonant;
//input string
cout<<"enter a string:";
cin.getline(string,30);
do
{
//displaying Menu
cout<<" MENU"<<endl;
cout<<"count the number of Vowels in the string"<<endl;
cout<<"count the number of Consonants in the string"<<endl;
cout<<"count both the vowels and the consonants in the string"<<endl;
cout<<"enter another string"<<endl;
cout<<" Exit program"<<endl;
//inputing choice
cout<<"enter choice";
cin>>choice;
switch (choice)
{
case 'A' :// function call to get vowels
Nvowels=Vowel_count(string);
cout<<"number of vowels is:"<<Nvowels<<endl;
break;
case 'B':
Nconsonant=Consonant_count(string);
cout<<"Number of consonants is:"<<Nconsonant<<endl;
break;
case 'C':// function call to get number of vowel and consonant
Nvowels=Vowel_count(string);
Nconsonant=Consonant_count(string);
cout<<"number of vowels is:"<<Nvowels<<endl;
cout<<"number of consonant is:"<<Nconsonant<<endl;
break;
case 'D'://inputting another string
cout <<"enter another string:";
fflush(stdin);
cin.getline (string,30);
break;
case 'E':exit (0);
break;
}
}
while (choice!='E');
system ("pause");
}
int Vowel_count(char *str)
{
int count=0;
while (*str!='')
{
if(*str=='a'||*str=='e'||*str=='i'||*str=='o'||*str=='u')
count++;
str++;
}
return count;
}
int Consonant_count(char *str)
{
int count=0;
while (*str!='0')
{
if(char *str,!='a'&&char *str,!='e'&&char *str,!='i'&&char *str,!='o'char *str,!='u'),
count++;
str++;
}
return count;
}
Explanation / Answer
replace if(char *str,!='a'&&char *str,!='e'&&char *str,!='i'&&char *str,!='o'char *str,!='u'), count++; str++; by if (*str !='a' && *str !='e'&& *str !='i' && *str !='o' && *str !='u') { count++; str++; }
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.