i need help on how to create a C++ program that will input string of characters and will count the number of different vowels, consonants and symbols included in the string.
Input a string => "program!"
total letter 'a' => 1
total letter 'e' => 0
total letter 'i' => 0
total letter 'o' => 1
total letter 'u' => 0

total vowels => 2
total consonants => 5
total symbols => 1
total characters => 8

Recommended Answers

All 3 Replies

Create 5 integers that will accumulate the counts for each vowel.

print prompt to enter string
accept keyboard input into std::string or character array variable

loop through each character in the string
beginning of loop
   test for vowel
   if 'a' then increment a-counter
   else if 'e' then increment e-counter
   etc. for each vowel
end of loop

print the value of each vowel counter

Someone said that a program is algorithm+data structures.
Ancient has given you the algorithm. I would like to recommend a data structure:map to store the number of occurrence of each vowel.

1. Niklaus Wirth. Algorithms + Data Structures = Programs. Prentice Hall etc...
2. The char type values range provides much (much) more suitable data structure: a simplest 1D array. Be careful: char may be signed or unsigned (it's an implementation-defined issue)...
;)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.