Question #39324

Write a program that reads in characters from the user. Assume they will give you correct input, which corresponds to capital letters (A-Z) and lower-case letters (a-z). Count up the number of vowels entered versus consonants. The program will terminate when the user gives, as input, an exclamation point (!). Use a switch statement where possible.
1

Expert's answer

2014-03-04T09:53:51-0500

Answer on Question#39324- Programming, C++

1. Write a program that reads in characters from the user. Assume they will give you correct input, which corresponds to capital letters (A-Z) and lower-case letters (a-z). Count up the number of vowels entered versus consonants. The program will terminate when the user gives, as input, an exclamation point (!). Use a switch statement where possible.

Solution.


#include <iostream>
#include <ctype.h>
using namespace std;
int main(int argc, char* argv[])
{
    int ivwl=0, icnst=0;
    char ch;
    char *vowels[]={"A", "E", "I", "O", "U"};
    char *consonants[]={"B", "C", "D", "F", "G", "H", "J", "K", "L", "M", "N", "P", "Q", "R", "S", "T", "V", "W", "X", "Y", "Z"};
    while(1)
    {
        cout<<">> ";
        cin>>ch;
        for(int i=0; i<sizeof(vowels) / sizeof(vowels[0]); i++)
            if(*vowels[i]==ch) { ivwl++; }
        for(int i=0; i<sizeof(consonants) / sizeof(consonants[0]); i++)
            if(*consonants[i]==ch) { icnst++; }
        if(ch=='!'){break;}
    }
    cout<<"============================;";
    cout<<endl<<"Vowels: "<<ivwl<<" "<<"Consonants: "<<icnst<<endl;
    cin.get();
    cin.get();
    return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!
LATEST TUTORIALS
APPROVED BY CLIENTS