Need a little help

I was wondering if i could have someone look over my code and see if i did anything wrong. I'm doing a HW assignment where the user enters a sequence of letters and the program outputs the number of vowels in the sequence. im getting the correct values but for some reason mindtap is not accepting the answer. would love some feedback!

Syntax:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#include<iostream>
#include<string>

using namespace std;

string x;
bool isvowel(char x )
{
  x = toupper(x);
	if ((x =='A' )||(x == 'U')||(x=='E')||(x=='O')||(x== 'I') )

		return true ;
	else
		return false ;

}
int main ()
{
  cout << "enter a sequence of characters: ";
  getline(cin, x);
  
  string testString(x);
  int numVowels(0);
	for(int i=0;i < (int)testString.size();++i)
	{
		char charToTest = testString.at(i);

		if(true == isvowel(charToTest))
		{
			numVowels++;
		}
	}
  cout <<  numVowels << " vowels in this sentence" <<  endl;
  return 0;
}


Not wrong per se, but there is no need for string x; to be a global variable. Declare it inside of main.

if (true == isvowel(charToTest)) { ... } is equivalent to just doing: if (isvowel(charToTest)) { .. }

You should #include <cctype> to use functions like toupper.

There is no need make your second string (testString) when your first string (x) already exists. I would rename x to be testString in your main function.

_________________________________________________

But the important part:
DaMcGruber wrote:
mindtap is not accepting the answer.
We have no idea what exact format the automated grading program is using, so we would need to know more details. I suggest you read the prompt very closely and see if there's any place you deviate from it.
Last edited on
Topic archived. No new replies allowed.