Keeps reading the cout no matter what the string is.

So I have set up predefined keywords as chars and it checks if the mood input is equal to first the weezer char, then the nirvanaisbad chars, etc etc, and if it isn't prelogged anywhere it will just move on to confirmation. But no matter what I enter, it saya "Get laid, virgin" no matter what. I have spent 3 days trying so many different things and I just want to start working on other parts of the program. All help appreciated! Code below.

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
  #include <string>
#include <string.h>
#include <iostream>
#include <vector>

using namespace std;

int main()
{
        string mood;
        string answer;

   char const * weezerresponses = {"weez"};

   char const * nirvanabadresponse = {"i dont like nirvana" "i don't like nirvana" "i do not like nirvana" "fuck nirvana" "nirvana sucks" "nirvanas trash" "nirvana is trash" "nirvanas garabage"
                                "nirvana is garbage" "nirvana blows" "nirvana sucks balls" "nirvanas ass" "nirvana is ass"};

   char const * britishpunk = {"u/britishpunk149" "britishpunk149"};
    start:

    cout << "Oh hey! How are you feeling today?" << endl;

    getline(cin, mood);


        // responses to phrases in the mood string

           if (mood.find(weezerresponses) )
           {
               cout << "Get laid, virgin." << endl;
           }




          if (mood.find(nirvanabadresponse))
         {
             cout << "Yeah... you're right :/" <<endl;
         }


         else if (mood.find(britishpunk))

         {
             cout << "Oh yeah man! I freaking LOVE u/britishpunk149!!! I am her biggest fan :D" <<endl;
         }

         else{}



         // confirms mood
        cout<<endl;
     cout << "You answered " << mood << ". Is that correct? " << endl;

     getline(cin, answer);



     //confirms the users answer
     if (answer == "yes" || answer == "yeah" || answer == "Yes" || answer == "Yes")
     {
        cout << endl;
         cout << "Okay cool!" <<endl;
     }

        // if answer string is no
            else {
             std::cin.clear();
              std::cin.ignore();
                goto start;
            }


    return 0;
}
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
#include <string>
#include <iostream>
#include <cctype>

// return true if the string matches one of those in the array
template < typename ARRAY > bool is_one_of( const std::string& str, const ARRAY& array ) {

    // range based loop: https://www.stroustrup.com/C++11FAQ.html#for
    for( auto&& phrase : array ) if( str == phrase ) return true ;
    return false ; // no match
}

// return string with lower case characters converted to upper case
std::string to_lower( std::string str ) {

    std::string result ;
    // https://en.cppreference.com/w/cpp/string/byte/tolower
    for( unsigned char c : str ) result += std::tolower(c) ;
    return result ;
}

int main() {

    // note: arrays of const pointers to const char
    const char* const weezerresponses[] = { "weez" } ;
    const char* const nirvanabadresponses[] = { "i dont like nirvana", "i don't like nirvana", "i do not like nirvana",
                                                "fuck nirvana", "nirvana sucks", "nirvanas trash", "nirvana is trash",
                                                "nirvanas garabage", "nirvana is garbage", "nirvana blows",
                                                "nirvana sucks balls", "nirvanas ass", "nirvana is ass" };
    const char* const britishpunkresponses[] = { "u/britishpunk149", "britishpunk149" };

    std::string mood ;
    std::cout << "Oh hey! How are you feeling today? " ;
    std::getline( std::cin, mood ) ;

    const std::string lc_mood = to_lower(mood) ; // converted to all lower case

    if( is_one_of( lc_mood, weezerresponses ) ) std::cout << "Get laid, virgin.\n" ;
    else if( is_one_of( lc_mood, nirvanabadresponses ) ) std::cout << "Yeah... you're right :/\n" ;
    else if( is_one_of( lc_mood, britishpunkresponses ) ) std::cout <<"Oh yeah man! I freaking LOVE u/britishpunk149!!! I am her biggest fan :D\n" ;
    else ; // std::cout << whatever
}
As C++17:

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
#include <string>
#include <iostream>
#include <algorithm>
#include <iterator>
#include <cctype>

template <typename cArray>
bool isin(const std::string& str, const cArray& array) {
	return std::find(std::begin(array), std::end(array), str) != std::end(array);
}

std::string to_lower(std::string str) {
	for (auto& c : str)
		c = static_cast<char>(std::tolower(static_cast<unsigned char>(c)));

	return str;
}

int main() {
	constexpr const char* weezerresponses[] {"weez"};
	constexpr const char* nirvanabadresponses[] {"i dont like nirvana", "i don't like nirvana", "i do not like nirvana",
												"fuck nirvana", "nirvana sucks", "nirvanas trash", "nirvana is trash",
												"nirvanas garabage", "nirvana is garbage", "nirvana blows",
												"nirvana sucks balls", "nirvanas ass", "nirvana is ass"};
	constexpr const char* britishpunkresponses[] {"u/britishpunk149", "britishpunk149"};

	std::string mood;

	std::cout << "Oh hey! How are you feeling today? ";
	std::getline(std::cin, mood);

	if (const auto lc_mood {to_lower(mood)}; isin(lc_mood, weezerresponses))
		std::cout << "Get laid, virgin.\n";
	else if (isin(lc_mood, nirvanabadresponses))
		std::cout << "Yeah... you're right :/\n";
	else if (isin(lc_mood, britishpunkresponses))
		std::cout << "Oh yeah man! I freaking LOVE u/britishpunk149!!! I am her biggest fan :D\n";
	else
		std::cout << "of course I've got this terrible pain in all the diodes down my left hand side\n";
}

Topic archived. No new replies allowed.