In: Computer Science
C++, Need to create a code that will calculated the statistics for character input?
This is the prompt for the code. I truly understand nothing of what it's asking.
Ask the user for one character (terminated by a carriage return).Using flow control, classify the character into one of these categories:
1) vowel
2) consonant
3) digit (0-9)
4) other
Output the character input, its numeric decimal value, and the classification. Total up the number of each type of character entered. After the character is entered, ask the user if they want to continue (Y/N). When they enter N, you can stop prompting for more characters. Make sure to validate for Y or N data entry. Then display the total number of each type of characters entered.
Note : Could you plz go through this code and let me know if u
need any changes in this.Thank You
_________________
#include <iostream>
#include<cmath>
#include<iomanip>
using namespace std;
bool isVowel(char ch);
int main()
{
int cntVowel=0,cntConsonant=0,cntDigit=0,cntOther=0;
char ch,YorN;
while(true)
{
cout<<"Enter a character :";
cin>>ch;
if(isVowel(ch))
{
cntVowel++;
}
else if((ch>='A' &&
ch<='Z') ||(ch>='a' && ch<='z') &&
!isVowel(ch))
{
cntConsonant++;
}
else if(isdigit(ch))
{
cntDigit++;
}
else
{
cntOther++;
}
cout<<"\nDo you Want to
continue(Y/N):";
while(true)
{
cin>>ch;
if(ch=='y'||ch=='Y')
{
break;
}
else if(ch=='N'
|| ch=='n')
{
cout<<"Vowels :"<<cntVowel<<endl;
cout<<"Consonants
:"<<cntConsonant<<endl;
cout<<"Digits
:"<<cntDigit<<endl;
cout<<"Others
:"<<cntOther<<endl;
exit(0);
}
else
{
cout<<"Invalid choice.Re-Enter :";
}
}
}
return 0;
}
bool isVowel(char ch)
{
if(ch=='a' || ch=='A'|| ch=='e' ||
ch=='E'
||ch=='i' || ch=='I'||
ch=='o' ||
ch=='O'|| ch=='u' || ch=='U')
{
return true;
}
else
{
return false;
}
}
____________________________
// Output:
_______________Could you plz rate me well.Thank
You