assignment8b3.cpp:44:19: warning: comparison of integers of different signs:
'int' and 'size_type' (aka 'unsigned long') [-Wsign-compare]
for (int i = 0; i < str.size(); i++)
~ ^ ~~~~~~~~~~
assignment8b3.cpp:53:19: warning: comparison of integers of different signs:
'int' and 'size_type' (aka 'unsigned long') [-Wsign-compare]
for (int i = 0; i < str1.size(); i++)
~ ^ ~~~~~~~~~~~
assignment8b3.cpp:67:19: warning: comparison of integers of different signs:
'int' and 'size_type' (aka 'unsigned long') [-Wsign-compare]
for (int i = 0; i < str.size(); i++)
[code]
#include <iostream>
#include <string>
using namespace std;
// Function declarations
string removeVowels(string str);
bool containsVowel(string str);
int main()
{
// Declaring variable
string str;
// Getting the string entered by the user
cout << "Enter the string :";
std::getline(std::cin, str);
/* calling the function by passing
* the user entered string as argument
*/
string str1 = removeVowels(str);
/* Displaying the string after
* removing vowels and convert it into upper case
*/
cout << "String after removing vowels and convert to uppercase:" << str1 << endl;
// calling the function
bool boolean = containsVowel(str1);
// Based on the boolean value display the message
if (boolean)
cout << "The String '" << str1 << "' does'nt contains a single vowel" << endl;
else
cout << "The String '" << str1 << "' contains vowel" << endl;
return 0;
}
/* this function will remove the vowels
* in the string and convert it into upper case
*/
string removeVowels(string str)
{
string str1 = "";
for (int i = 0; i < str.size(); i++)
{
if (str.at(i) != 'A' && str.at(i) != 'a' && str.at(i) != 'E' && str.at(i) != 'e'
&& str.at(i) != 'I' && str.at(i) != 'i' && str.at(i) != 'O' && str.at(i) != 'o'
&& str.at(i) != 'U' && str.at(i) != 'u')
{
str1 += str.at(i);
}
}
for (int i = 0; i < str1.size(); i++)
{
if (str1.at(i) >= 97 && str1.at(i) <= 122)
{
str1.at(i) = str1.at(i) - 32;
}
}
return str1;
}
// Checking the string contains vowel or not
bool containsVowel(string str)
{
int count = 0;
for (int i = 0; i < str.size(); i++)
{
if (str.at(i) != 'A' || str.at(i) != 'a' || str.at(i) != 'E' || str.at(i) != 'e'
|| str.at(i) != 'I' || str.at(i) != 'i' || str.at(i) != 'O' || str.at(i) != 'o'
|| str.at(i) != 'U' || str.at(i) != 'u')
{
Look at this snippet: for (int i = 0; i < str.size(); i++)
The problem is that str.size() returns a size_t not an int. A size_t is an implementation defined unsigned type, an unsigned long on your system. To fix this problem you should use a size_t for i.