Hey there, I need some help with a program I am making. When you type in certain text, it randomly prints from set responses. I have it using the random function in order to print responses, however, I am having a problem. I keeps printing out irrelevant text EX: You enter "Fight me" It'll say " "Goodbye." which is a response to if you say "hello"
#include <iostream>
#include <string>
#include <windows.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#pragma comment(lib, "Winmm.lib")
usingnamespace std;
int main() {
string c;
int re;
cout << " Welcome to S.A.M." << endl;
cout << endl;
cout << endl;
cout << " Please refrain from using Captaial Letters or Special Charcters while using S.A.M.! It makes him Angry!" << endl;
cin >> c;
if (c == "hi" || "hello" || "hi sam" || "hello there" || "hello sam" || "hey" || "sup" || "hey there sam") {
srand(time(0));
re = rand() % 8 + 1;
if (re == 1) {
cout << "What's up you piece of trash." << endl;
cin >> c;
}
if (re == 2) {
cout << "Goodbye." << endl;
cin >> c;
}
if (re == 3) {
cout << "Fuck off my dude." << endl;
cin >> c;
}
if (re == 4) {
cout << "Why hello there, asshole." << endl;
cin >> c;
}
if (re == 5) {
cout << "Did I give you permission to greet me? Didn't think so." << endl;
cin >> c;
}
if (re == 6) {
cout << "Fuck off." << endl;
cin >> c;
}
if (re == 7) {
cout << "Greetings are for faggots, faggot." << endl;
cin >> c;
}
if (re == 8) {
cout << "Don't try and talk to me until you lose your virginity, m'kay?" << endl;
cin >> c;
}
}
if (c == "lets play" || "want to play a game" || "want too play a game" || "wanna play a game" || "lets do something" || "lets play something") {
re = rand() % 9 + 12;
if (re == 9) {
cout << "I'd rather not." << endl;
cin >> c;
}
if (re == 10) {
cout << "Let's play the game, 'who should we eat first' and then not make it a game." << endl;
cin >> c;
}
if (re == 11) {
cout << "Anything but COD" << endl;
cin >> c;
}
if (re == 12) {
cout << "I'd rather hang from a noose" << endl;
cin >> c;
}
}
if (c == "fight me" || "lets fight" || "wanna go") {
re = rand() % 15 + 13 ;
if (re == 13) {
cout << "I don't fight 12 year olds who play TF2, but if you insist." << endl;
cin >> c;
}
if (re == 14) {
cout << "Gary Johnson has a better chance of winning the 2016 election than you do beating me in a fight." << endl;
cin >> c;
}
if (re == 15) {
cout << "I will destroy you like Lisa will destroy ISIS." << endl;
cin >> c;
}
else {
re = rand() % 1000 + 1010;
if (re == 1000) {
cout << "Don't make me tell Hillary Clinton that you have information that could lead to her arrest." << endl;
cin >> c;
}
if (re == 1001) {
cout << "You smell like the rotten asshole of a roadkill skunk that was drenched in beer." << endl;
cin >> c;
}
}
}
}
Your if statement. This for example - (c == "fight me" || "lets fight" || "wanna go")
Is wrong. You have to explicitly type c == everytime. It should look like this -
(c == "fight me" || c == "lets fight" || c == "wanna go") // Note c== after every ||
2.
cin >> c; The "cin" operator stops reading at white space. So if you type "Fight me" It will stop after "fight". "me" will not be read. What you have to use to get the entire sentence with space is called getline - http://www.cplusplus.com/reference/string/string/getline/