Phrase 1

#include <iostream> #include <string> using namespace std; int main() { string phrase = ""; string digits = "0123456789"; string marks = "!?.,;:\'\"\\/_*"; string vowels = "AaEeIiOoUuYy"; int digitsLength = digits.length(); int marksLength = marks.length(); int vowelsLength = vowels.length(); cout << "Enter a phrase: "; getline(cin, phrase); int totalDigits = 0; int totalMarks = 0; int totalVowels = 0; int total = phrase.length(); for (int i = 0; i != total; ++i) { for (int j = 0; j <= digitsLength; ++j) if (phrase[i] == digits[j]) totalDigits += 1; for (int m = 0; m <= marksLength; ++m) if (phrase[i] == marks[m]) totalMarks += 1; for (int v = 0; v <= vowelsLength; ++v) if (phrase[i] == vowels[v]) totalVowels += 1; } cout << "Total of vowels: " << totalVowels << endl; cout << "Total of marks: " << totalMarks << endl; cout << "Total of digits: " << totalDigits << endl; cout << "Total: " << total << endl; float percentVowels = 0.0; percentVowels = 1.0*totalVowels / total * 100; cout << "Percent of vowels at phrase: " << percentVowels << " %"; return 0; }

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.