No match for 'operator=='

I am having an issue with some lines, the code will not compile.

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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
#include <cstdlib>
#include <iostream>
#include <cctype>
using namespace std;

int main(int argc, char *argv[])
{
    string question;
    string repeat;
    int answer;
    
    do{
    cout << "Please ask a question for the Magic 8 Ball\n" << endl;
    getline(cin, question);
    
    answer = rand() % 20 + 1;
    
    switch (answer)
    {
           case 1:
                cout << "it is certain" << endl;
                cout << "affirmative"<<endl;
                break;
           case 2:
                cout << "it is decidedly so" << endl;
                cout << "affirmative"<<endl;
                break;
           case 3:
                cout << "most likely" << endl;
                cout << "affirmative"<<endl;
                break;
           case 4:
                cout << "signs point to yes" << endl;
                cout << "affirmative"<<endl;
                break;
           case 5:
                cout << "reply hazy, please ask again" << endl;
                cout << "neutral"<<endl;
                break;
           case 6:
                cout << "ask again later"<<endl;
                cout << "neutral"<<endl;
                break;
           case 7:
                cout << "dont count on it"<<endl;
                cout << "negative"<<endl;
                break;
           case 8:
                cout << "my sources say no"<<endl;
                cout << "negative"<<endl;
                break;
           case 9:
                cout << "my reply is no"<<endl;
                cout << "negative"<<endl;
           case 10:
                cout << "very doubtful"<<endl;
                cout << "negative"<<endl;
           case 11:
                cout << "outlook not soo good"<<endl;
                cout << "negative"<<endl;
           case 12:
                cout << "without a doubt" << endl;
                cout << "affirmative"<<endl;
                break;
           case 13:
                cout << "yes - definitely" << endl;
                cout << "affirmative"<<endl;
                break;
           case 14:
                cout << "you may rely on it" << endl;
                cout << "affirmative"<<endl;
                break;
           case 15:
                cout << "yes" << endl;
                cout << "affirmative"<<endl;
                break;
           case 16:
                cout << "outlook good" << endl;
                cout << "affirmative"<<endl;
                break;
           case 17:
                cout << "as i see it, yes" << endl;
                cout << "affirmative"<<endl;
                break;
           case 18:
                cout << "better not tell you now" << endl;
                cout << "neutral"<<endl;
                break;
           case 19:
                cout << "cannot predict now" << endl;
                cout << "neutral"<<endl;
                break;
           case 20:
                cout << "concentrate and ask again" << endl;
                cout << "neutral"<<endl;
                break;
           }
    
    cout << "Would you like to ask another question?" << endl;
    getline(cin, repeat);
    repeat = toupper (repeat);
} while (repeat == 'Y');
    
    system("PAUSE");
    return EXIT_SUCCESS;
}


 

getline(cin, repeat);
repeat = toupper (repeat);

the compiler says "no matching function for call to 'toupper(std::string&)' "
as well as "canidates are: int toupper(int)" and "no match for 'operator==' in 'repeat==Y'

ive searched online and im just not sure how to fix this. im very new to c++, sorry for using using namespace std in advance.
Last edited on
toupper can only transform a single char and not a string.
Also you can't compare a string with a single char.
The easiest solution should be to use a char for repeat.
1
2
3
4
  cout << "Would you like to ask another question?" << endl;
  cin >> repeat; // don't forget to change repeat to a char
  cin.ignore(255, '\n'); // remove trailing '\n'
  repeat = toupper (repeat);
The toupper function only works for single characters. If you want it convert the whole string to upper case you need to loop through the string and use toupper on each character.
thank you very much thomas, i am having a difficult time learning the language (first programming class) and did not realize that i could not toupper a string. also, the line that says "cin.ignore(255, '\n'); // remove trailing '\n'" what does this mean? what are you ignoring?
For example if you have a char var and type 'a' and return in the console only the 'a' gets stored in the variable. The '\n' will stay in the input buffer and might cause problems with the following inputs.

Not sure if you have a good textbook already, but if you are serious grab a copy of this
The C++ Programming Language 4th ed by Bjarne Stroustrup
The author is the creator of C++ so he knows what he is writing about.
Topic archived. No new replies allowed.