I dont understade why this is not working I get Build Debu
I dont understade why this is not working.
I get \" ||=== Build: Debug in pp1 (compiler: GNU GCC Compiler) ===|
main.cpp|18|error: a function-definition is not allowed here before \'{\' token|
main.cpp|12|warning: unused variable \'vowelCount\' [-Wunused-variable]|
main.cpp|52|error: expected \'}\' at end of input|
/*Write a value-returning function, isVowel, that returns the value true if a
given character is a vowel and otherwise returns false. Write a program that
prompts the user to input a sequence of characters and outputs the number of
vowels, using the function isVowel.
Turn in your source code which should be commented as follows:
Analysis at the top of the file
Function analysis, preconditions, and postconditions after each function prototype
Major tasks identified as comments in main function
Comments in functions as needed
*/
#include <iostream>
#include <locale>
#include <string>
using namespace std;
int main()
{
string chars;
int vowelCount = 0;
typedef enum{
IsVowel, NotVowel
}CharVowelType;
CharVowelType IsVowel(char c) {
switch (c){
case \'A\':
case \'E\':
case \'I\':
case \'O\':
case \'U\':
case \'a\':
case \'e\':
case \'i\':
case \'o\':
case \'u\':
return IsVowle;
default:
return NotVowel;
}
}
string chars;
int vowelCount = 0;
Cout<< \"Enter a word or sentence that you want the vowels counted.\"<<endl;
getline(cin, chars);
for (int i= 0; i< chars.length(); i++){
int value = IsVowle(char.at(i));
if (value == IsVowle){
vowelCount++;
}
}
cout<< \"There were \"<< vowelCount <<\" vowels in your word or statement.\"<<endl;
return 0;}
Solution
#include <iostream>
#include <locale>
#include <string>
using namespace std;
typedef enum{
IsVowel, NotVowel
}CharVowelType;
CharVowelType IsVowels(char c) {
switch (c){
case \'A\':
case \'E\':
case \'I\':
case \'O\':
case \'U\':
case \'a\':
case \'e\':
case \'i\':
case \'o\':
case \'u\':
return IsVowel;
default:
return NotVowel;
}
}
int main()
{
string chars;
int vowelCount = 0;
cout<< \"Enter a word or sentence that you want the vowels counted.\"<<endl;
getline(cin, chars);
for (int i= 0; i< chars.length(); i++){
int value = IsVowels(chars.at(i));
if (value == IsVowel){
vowelCount++;//
}
}
cout<< \"There were \"<< vowelCount <<\" vowels in your word or statement.\"<<endl;
return 0;}
output
Enter a word or sentence that you want the vowels counted.
nagaraju is a good boy
There were 9 vowels in your word or statement.


