#include <iostream>
#include <string>
usingnamespace std;
int countVowels(string aLetter, string aString);
int main()
{
string enteredString;
cout << "Please enter a string: ";
getline(cin, enteredString);
int a = countVowels("a", enteredString);
int e = countVowels("e", enteredString);
int i = countVowels("i", enteredString);
int o = countVowels("o", enteredString);
int u = countVowels("u", enteredString);
cout << "The letter a appears " << a << " time/s." << endl;
cout << "The letter e appears " << e << " time/s." << endl;
cout << "The letter i appears " << i << " time/s." << endl;
cout << "The letter o appears " << o << " time/s." << endl;
cout << "The letter u appears " << u << " time/s." << endl;
return 0;
}
int countVowels(string aLetter, string aString)
{
int count = 0;
string extractedLetter;
for (int i = 0; i < aString.length(); i++)
{
extractedLetter = aString.at(i);
if (extractedLetter == aLetter)
count++;
}
return count;
}
is giving me the following warning:
(34) : warning C4018: '<' : signed/unsigned mismatch
The return value for string.length() in an unsigned int and i is a signed int. As the value of an unsigned int can exceed the top range of a signed int, the compiler issues a warning.
Try: for (unsignedint i = 0; i < aString.length(); i++)