Sentinel not working....

I'm not sure why this isn't working, but this is my error message:


Error] no match for 'operator!=' (operand types are 'std::string {aka std::basic_string<char>}' and 'const int')


1
2
3
4
5
6
7
8
9
10
11
int main ()
{	

	const int SENTINEL = 0;		// Sentinel value. 
	
	// Request input string unless sentinel is entered.  
	
	cout << "Enter a word or series of words. " << '\n';
	cout << "Or, enter " << SENTINEL << " to quit. " << endl;
	cin >> withVowel;
	while (withVowel != SENTINEL)



Last edited on
How have you defined withVowel? I read the error message as saying you're trying to compare values with two different data types.
Yeah, that was the problem I was able to fix that, but now I'm struggling because I just realized the code only removes vowels from the first word and not from a sentence :(...

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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#include <iostream>
#include <string>
using namespace std;


void removeVowel(string&);			// Removes vowels from input string.
string withVowel;				// Will be used to read user input. 

int main ()
{	

	const string SENTINEL = "0";		// Sentinel value. 
	
	// Request input string unless SENTINEL is entered.  
	
	cout << "Enter a word or series of words. " << '\n';
	cout << "Or, enter " << SENTINEL << " to quit. " << endl;
	cin >> withVowel;
	
	// In case of SENTINEL:
	
	while (withVowel == SENTINEL)
	{
		cout << "***" << endl;
	}

	// Run loop.
	
	removeVowel(withVowel);
	
	// Display the string without vowels.
		
    cout << "The word(s) entered reflecting only consonants: " << withVowel << endl;
    
    return 0;
}

	void removeVowel(string& withVowel)
	{
		int i = 0;
		int length = int(withVowel.length());
		while (i < length)
	{
		if (withVowel.at(i) == 'a' || 
		    withVowel.at(i) == 'A' || 
		    withVowel.at(i) == 'e' || 
		    withVowel.at(i) == 'E' ||
		    withVowel.at(i) == 'i' || 
		    withVowel.at(i) == 'I' || 
		    withVowel.at(i) == 'o' || 
		    withVowel.at(i) == 'O' || 
		    withVowel.at(i) == 'u' ||
		    withVowel.at(i) == 'U')
			
			{
				withVowel.erase(i, 1);
				length = int(withVowel.length());
			}
	    	else i++; 
		}
                 
	// Display the string without vowels.	
                
	cout << removeVowel << endl;
	
	} 

Topic archived. No new replies allowed.